C/C++ :: Storing IPv6 In Character Array?
Jul 11, 2014
Its been too long since I have had to fiddle bits and I am coming up short.
Bottom line is the new IPv6 ip address representation is of the format:
xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
These come to me as hex values for example:
2001:7D7E:0000:0000:111A:222B:333C:4444
I want to store this in a char array, of integers of size char_addr[16] where each byte represents the integer representation of each xx pair thus
char_addr[0]=32 (20) *note address above
char_addr[1]=1 (01)
char_addr[2]=125 (7D)
char_addr[3]=126 (7E)
char_addr[4]=0 (00)
...
char_addr[15]=68 (44)
So I am having trouble filling that char_addr array.
View 4 Replies
ADVERTISEMENT
Jan 30, 2013
I am creating a program and am having trouble with one part. The input file looks like:
Code:
2
3
Bill Jeff Steve
Linda Brittany Jessica
3 1 4
2 1 9
8 3 7
6 4 9
4 8 9
6 9 4
Where I am stuck is putting the numbers into the string array. For example, Bill's scores should be set up as Bill's scores should be set as
Code: bill_score = {3, 1, 4}
and when this code is ran
Code:
for (i=0; i<3; i++) {
printf("%s - ", men[i]);
[Code].....
View 4 Replies
View Related
Jan 6, 2014
I am reading data from a text file into a program. I am well aware of the subtle distinctions in the mode of data input/entry when using the stream extraction operator, the get() function, and the getline() function.
My problem is that all of them do not read and/or store the newline character alongside the data read!
Any function that reads and stores data and the terminating newline character together??
View 1 Replies
View Related
Feb 24, 2015
I want to examine every packet of a pcap trace file and if packet n+1 source address == packet n destination address && packet n+1 destination address == packet n source address i want to get the time between those 2 packages.
Problem: I can't compare the ipv6 adresses of src and destination.
comparing src and src is no problem. dst with dst as well
Code: ....
handle = pcap_open_offline(argv[fnum], errbuf);
while (packet = pcap_next(handle,&header))
{
...
struct ip6_hdr *ip_hdr = (struct ip6_hdr *)packet;
if (memcmp(&(ip_hdr->ip6_dst),ipv6_src,sizeof(ip_hdr->ip6_dst)))
{
.....
[code]....
if i try to compare these adresses i will never get a match. But i use a trace file with much matches. Do i need a offset in pkt_ptr? I saw some examples which deals with it.
Code:
uint32_t* test = (uint32_t*)ipv6_dst;
for (uint32_t j=0;j<sizeof(ip_hdr->ip6_dst);j++)
{
printf ("%x", *(test+j));
}
printf ("
[Code] ......
with given addresses:
Source: 2001:6f8:1c2c:2000:54c2:b056:f097:2830
Destination: 2a01:238:43f5:d900:2bf:784a:e3f8:9cd7
View 1 Replies
View Related
Jul 4, 2014
Can we do this :
Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];
View 3 Replies
View Related
May 17, 2014
#include <iostream>
#include<fstream>
int decryption(int);
int multiply(int,int[][2]);
using namespace std;
main(){
int n;
ifstream inFile;
inFile.open ("out.txt");
[Code] .....
I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:
line 33: cout<<m[i][j]<<" ";
View 4 Replies
View Related
Jul 31, 2013
Take for example two arrays.
int A[2][2][2] = { {{1, 2}, {3, 4}},{{ 5, 6}, {7, 8}} };
int B[1]
I want to store the entire array "A" into B[1]. Is it possible?
View 2 Replies
View Related
Mar 27, 2013
I am having trouble storing strings into an array. Basically I have a console program where it has an option. This is just an example;
Code:
char name[max];
char listofnames[maxname];
int counter;
....
printf("Add names
");
And how can I print it?
View 9 Replies
View Related
May 4, 2013
So i have a program with the structure
Code:
char record[20];
typedef struct{
int id;
char title[20];
char subject[20];
char faculty [20];
int level;
char fname[25];
}report;
int recno,i;
report list[100];
I need to store the hundred records into a file. What are the functions and elements i should use/introduce.
View 2 Replies
View Related
May 2, 2013
How do I go about storing info to an array of class?I need to do something like this:
info[count] = ReadNameRating(n, r);
Where info is an array of my own class and ReadNameRating reads the name and rating which is two of the variables handled by that class.
View 2 Replies
View Related
Sep 27, 2013
I have a base class Building. Then come its children classes - Commercial Building and Residential Building. The third level is composed of Apartment and House classes, both inherit from Residential Building.
I need to create an array of 20 elements that will store info about all these different types of buildings(Commercial Building,Residential Building,Apartment, House). How should I proceed?
View 5 Replies
View Related
Oct 2, 2012
I want to create filenames such as Query.student.1.bin and save them in an array. I have no problem when I don't include a "." between student and number "1" but as I add a "." there my code does not run. ( it does complie but crashes during the run)
string *filename_str;
filename_str =new string[Number_X_Axis];
for(i=0;i<Number_X_Axis;i++)
filename_str[i]="Query."+Table_Name+"."+convertInt(i)+".bin";
View 2 Replies
View Related
Dec 16, 2014
Code:
for(int i = 0 ; i < SIZE ; i ++)
{
scanf("%d" , & selection[i]);
srand((unsigned) time(&t));
draw[i] = rand() % 50; //feeling could be a problem with this line of code :::::
}
is it possible to do this. i am trying to get 6 different numbers stored into 6 elements of an array . this is the piece of the code i think there is a problem with. ie my program scans the numbers and then crashes at this point so think it could be something to do with the commented line?
View 2 Replies
View Related
Sep 12, 2013
Is something like this possible and if not how can I make this work?
fscanf(in, "%d %d %d", &i, &x, &arr[i+x]);
View 4 Replies
View Related
Jan 4, 2013
For some reason the integer array, arr[100][50], declared in main is not storing the correct values when passed through the function charArrayToIntArray.
I made an output right in the function to show how the array is not keeping the proper values, although when I output the array from within the loop in the function, it shows the correct values.
/*
infile.txt:
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676 ...........
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <iomanip>
using namespace std;
void fileToCArray(string carr[100]); // from text file: inputs the 100 50-digits number into an array of 100 50-character
[Code] ....
View 4 Replies
View Related
Oct 9, 2013
The aim is : If i have a natural number [max 5 digits] (say) n=13579. Then a[4]=1, a[3]=3, a[2]=5. a[1]=7. a[0]=9.
I start with a[4]= n/10000 .. then n= n - a[4]*10000;
then a[3]= n/1000. .. n= n - a[3]*1000;
i.e a[i]= n/10^i .... n= n - a[i]*10^i;
To reduce code size i used a for loop. The code is free from any syntax errors.
Its the "output" that is weird. I enter 13579 and what the program process is:
a[4]=1 a[3]=3 a[2]=5 a[1]=8 a[0]=5
Same goes for other numbers too.. leaving the most significant digit , the rest digits are just out of the logic!!
I am using CodeBlocks 12.11 and compiler is GNU GCC compiler.
Here is the output window: [URL] ....
Here is the code:
#include<iostream>
#include<math.h>
using namespace std;
int main() {
int n,a[5],i,t,dec,divisor; // n: storing number; t: copy of n,
[Code] .....
View 2 Replies
View Related
Mar 4, 2013
here is my problem given below Input values (say 10) from user in array, if the value is even then place at even index else at odd index. Then how could i solve this problem?
View 2 Replies
View Related
Oct 4, 2014
Trying to make a program that stores a sequence of integers in an array by using functions. This is my code so far:
# include <iostream>
using namespace std;
int Sequence_Length(int seq_length)
{
[Code]....
I get an error in the main, not completely sure how to "call" functions to the main..
View 5 Replies
View Related
Nov 20, 2012
I am unable to understand why is the output for this shows me the address of the stored array.
int main()
{
size_t k= 0 ;
char t[3][100] = { "hi", "di", "fi" } ;
char s[3][100] ;
[Code]....
View 5 Replies
View Related
Jun 14, 2013
The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?
Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^
[Code] ....
Is it just my compiler?
View 5 Replies
View Related
May 4, 2013
I'm trying to read in a file and store it in an array that is dynamically allocated of a struct (which I'm not sure how to do), then parse each line using strtok() from string.h. The idea is to separate the lines by date, subject, time, etc.
Since the array is a dynamically allocated of typdef struct, it's sorted by the date of each struct, with an intial size of 25. But whenever the array needs to be resized, it should be doubled.
View 1 Replies
View Related
Nov 5, 2013
I have been dealing with this problem for quite some time, I've been assigned to develop a program that can store products' information within structures (the number of products is undefined). I thought I should use an array of structures, but I don't know how to declare it properly. This is what I thought would work:
struct product {
string name;
string in_stock;
float sale_cost;
int id; }
prod [n]; //n being the undefined number of products the user will register/delete/modify
I already saw an example of array of structures, but it uses a defined number.
View 13 Replies
View Related
Oct 28, 2014
My main issue is that when I store just one value into a simple integer variable, it gives me a big negative number.
My goal is to store a file that reads like this into arrays:
2014 1 23
2012 2 15
2013 1 25
etc
Where I would have the first column in an array, the second in another and the third in third array since I am not allowed to use multidimensional.
View 5 Replies
View Related
Feb 16, 2015
I need to read input from a file , which contains multiple sentences of varying lengths. After each new line char, i need to store that sentence into an array.
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>
[Code].....
View 2 Replies
View Related
Apr 17, 2012
I just started learning about pointer and reference. * and &
The assignment is " Write a program that stores the following numbers in the array named miles:15,22,16,18,27,23, and 20. Have your program copy the data stored in miles to another array named dist, and then display the values in the dist array. YOur program should use pointer notation when copying and displaying array elements.
And this is what i have so far. But there is an error. I highlighted it with red. It says it's incompatible...
#include <iostream>
using namespace std;
const int arraynumb = 7; // declaration of keys: number of characters of keys
void copyfunc(int *[], int); // function initialized
int main() {
int miles[arraynumb] = {15, 22, 16, 18, 27, 23, 20};
[Code] ....
View 1 Replies
View Related
Jun 6, 2012
I am trying to use C# with C++, two different applications that work together.
In C# it is easy to get a byte array out of a string, by just using Encoding.Default.GetBytes(of-this-string);
I can pass bytes to my C++ program by just writing in the embedded resources. But this won't allow strings, as far as I know it can only be a byte array. C++ reads the embedded resources a LPBYTE.
So I try to send the string or message in byteform.
However the problem in C++ is that there is no Encoding.Default.GetString(xxx)
Would there be any other ways to send a message/sentence in bytearrayform and request it in C++ back to the original string?
View 14 Replies
View Related