i making program displays element of choice periodic table using file. try compare string line of file, doesn't work. how can fix comparison?
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char * line = null; char name_element[1000]; size_t len=0; ssize_t read; file*table; table=fopen("data.txt","r"); printf("please enter element looking for:\n"); scanf("%s",name_element); while ((read = getline(&line, &len, table))!=-1){ i=strcmp(name_element,line); if (strcmp(line,name_element)==0) { while ((read = getline(&line, &len, table))!=-1) { if(strcmp(line,"////")!=0) { printf("%s", line); } else { break; } } } } fclose(table); return 0; }
in future, may want include input file, in case part of problem.
assuming won't cause problems, strncmp() way go. format strncmp(str1, str2, n) n number of characters want compare.
Comments
Post a Comment