Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to scan a 2 dimensional array ? Need help.

Status
Not open for further replies.

ab1966

Programmer
Jul 3, 2001
6
0
0
US
Hi,

I am reading data from a file and building an unique array of string elements. I am novice in C. So need help.

Example : I have the following arrays :

StringOfElements[TOTAL_NO_OF_ELEMENTS][LEN_OF_ELEMENT]
Elements[LEN_OF_ELEMENT]

I am reading data from file and storing it in Elements[]. Now I need scan StringOfElements for any existing element. If it is not present I am going to add it. Can anybody help me either writing the code or a function to resolve this.

Thanks in advance.




 
I supose every "Element" is a string. Then, it should be something like that:

Code:
int i=0;
int found=0;

while(i<actual_no_of_elements && !found){
  if(!strcmp(Elements,StringOfElements[i]))
    found=1;
  else
    i++;
  }

if(!found){
  strcpy(StringOfElements[actual_no_of_elements],Elements);
  actual_no_of_elements++;
  }

This should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top