[below structure contains s1.name contain array of string name. to check if user entered name in that array list. i need to compare words by words. but my problem is that since string is stored in array. and string itself is an small array. so i dont know how can i reach to each single words of string stored in array.]

/*program to input students details in structure and display its out put and search availability of student by its name without using strcmp()*/

int main(){

int i,n;

struct school{
int regno;
char name[20];
int class;

printf("\n enter the no of details of student to be added\n");

printf("enter the student %d details\n", i);

printf("enter reg no");
printf("name ");
printf("class ");


printf("\n*****RESULT ARE AS FOLLOW*****\n");

printf(" NAME CLASS REG NO \n");
printf("%s %d %d ",s1[i].name,s1[i].class,s1[i].regno)

7 Years
Discussion Span
Last Post by cthoes

Firstly, use fgets to obtain your name string from the user. See this for a reference (it's a C++ site but it should be nearly the same).

Next look into ctype.h and there's a function tolower() that will help you if you don't know whether the text is in caps or not (you could test whether or not it was for each character but we can just transform the whole thing to lowercase). If you can't use that library, you can write your own very quickly, just add the correct amount to the char value (see ASCII table)

You can access the character n (0 to size-1) of the string in the ith (0 to size-1) structure as follows:
s1.name[n] so use tolower() on each char
as you compare that to yourstring[n]
where char * yourstring= "yourstringtomatch";
(put any bells, whistles,code to skip spaces etc in there too)
march your loop until you hit the null terminator in the string '\0' count the number of times they match, compare that to the length of the string and you're in business.

Post back if there are any issues.

Edited by jonsca: n/a


thanks buddy it work well ...i didnt know i can read each words by s1..name untill u helped me out. so thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.