473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Arrays and Multidimensiona l Arrays in C

158 New Member
Good day all,

First,
I am rather new to C programming or at least don't use it enough to get used to it.

My question,

What part of my script needs to do is monitor a port and record the PACKETS and WHO sent them into a multidimensiona l array. Also I want it to know if that IP address is already in the array and if it is just update the PACKET.

Like:
[Array][1] = [IP][PACKET]
[Array][2] = [IP][PACKET]

I know in C you have to declare variables first so the processor can allocate the right amount of memory, but in my program I will not know exactly how many packets there are going to be. It is safe to say (If I have to) that theres not going to be more than 100max .

And than in the end I need to return that array so a different function can use it.

How would i go about doing this?

First I know i need to declare my array/char with 100 slots with 2 slots in each of them. Let me know if this is correct.
Expand|Select|Wrap|Line Numbers
  1.  char * array[100][2]; 
Now for setting the values. (How do i search an array for a value)

In word form: search all number 0 slots in array for 2.0.0.2 if 1 array slot 1 = buf;
Expand|Select|Wrap|Line Numbers
  1.  
  2. array[i][0] = inet_ntoa(a.sin_addr); 
  3. array[i][1] = buf;
  4.  

Now for laughs lets try to print that data with printf()

Expand|Select|Wrap|Line Numbers
  1.     while(i < sizeof(array)) {  
  2.        printf("%d - %s\n", i ,array[i][0] );  
  3.     i++;
  4.       }   
  5.  
So all in all I think I have the method close to right (maybe not) but I am just doing a few little things wrong?

Thanks in advance for any help received?

Cheers :)
Jul 17 '08 #1
1 1434
Laharl
849 Recognized Expert Contributor
Read this Howto.

Added to make this long enough.
Jul 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6742
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would clearly be the most efficient way to do it, but it only works on a copy of the original array and not the original (which is counter intuitive in my...
6
15567
by: ubccis | last post by:
Hi. Does for each for on multidimensional arrays? For example, if one element of $in is $course_list and I want to echo all everything in course_list
2
1137
by: Terry | last post by:
Hi, can someone plz tell me how multidimensional arrays (like a 2-D array) are stored in memory? Are they like single dimensional arrays? Stored sequentially in one "row", so to say? Thanks Terry
5
545
by: whisper | last post by:
Hi: there is an issue that confuses me and the FAQ did not clarify it for me. (Sorry I am just learning!) Let say I define a multidimensional array in my main routine as follows: int arr={{0,1,2}, {3,4,2}}; and I pass the array as a parameter to a function declared by:
3
8187
by: Claire | last post by:
I have a multidimensional array defined as private double myArray = new double; The first column of the array contains X values, the other contains Y values I have a charting function defined as Add(Array XValues, Array YValues) How do I call the Add function, passing my array columns please. thanks
3
2187
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string multidimensionalArray = new string
3
1862
by: matthewburton | last post by:
Hi everyone, I'm trying to write a program that will search a body of text and replace certain words (say, A, B, and C) with different words that I think are more appropriate (A1, B1 and C1). I have a feeling that I need to do this through a multidimensional array. Am I on the right track? thanks, matt
9
2125
by: barmy_mad | last post by:
Hi I new to C# and trying to store/extract a collection of multidimensional arrays. For example; string a_DATA = new string object o_CON = new object for(int i=0;i<10;i++){ for(int j=0;j<3;j++){
5
1975
by: asdf | last post by:
I was told not to use the low-level language such as arrays which inherited from C, I want to know what can I use to substitute the C-style multidimensional arrays? Is there multidimensional vector?
12
5630
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var myGroups = ,,]; var myProducts = ,,,]; var newGroups = new Array();//Resulting Array function main() { for(i=0; i<myGroups.length; i++){
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.