Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

strcmp

Name: C newbie /r/ your help 2012-12-08 11:26

test01.txt is a file containing this:
stallman    richy    1154
the program should find stallman, then write the whole line.
The problem is strcmp is returning -9 in the search function.

#include<stdio.h>
#include<string.h>
FILE *f;
void search(){
    int i,r;
    i=r=0;
    char prname[15],lrname[15],ed;
    printf("lrname?\n");
    gets(lrname);
    puts(lrname);
        while(ed!='\t'){
        ed=fgetc(f);
        prname[i]=ed;
        i++;
        }
        prname[i]='\0';
        puts(prname);
        printf("ed is %c\n",ed);
//this line
        printf("compare %d\n",strcmp(lrname,prname));       
if(strcmp(lrname,prname)==0){
            r=1;
            while(ed!='\n'){
                printf("%c",ed);
                ed=fgetc(f);
            }
        }else{printf("nope\n");}
}
int main(){
    f=fopen("test01.txt","r");
    search();
    fclose(f);

    return 0;
}

thanks.

Name: Anonymous 2012-12-08 11:29

gets(lrname);
Cow disgusting

Name: Anonymous 2012-12-08 11:30

o wait it's prname[i-1]='\0'.

Name: Anonymous 2012-12-08 11:32

>>2
what's wrong with gets?

Name: Anonymous 2012-12-08 11:33

learn python instead

Name: Anonymous 2012-12-08 11:34

>>4
Check mine.

Name: Anonymous 2012-12-08 11:37

Holy fuck you're dumb.

Name: Anonymous 2012-12-08 15:25

( ͡° ͜ʖ ͡°)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List