c - strstr with udp client string and file string -


i'm sending string udp client udp server. server's job check if string exists anywhere within textfile archive.txt.

the problem getting strstr returns null, if second string in first.

char msg[1000]; file *archive; archive = fopen("archive.txt", "r"); char line[53]; char *testing; 

. . .

        len = sizeof(cliaddr);         n= recvfrom(sockfd,msg,1000,0,(struct sockaddr *)&cliaddr,&len);         sendto(sockfd,msg,n,0,(struct sockaddr *)&cliaddr,sizeof(cliaddr));         msg[n]=0;         while(fgets(line, 53, archive) !=null)         {             testing = strstr(line, msg);              if(testing!=null)                {printf("%s\n","success");}             else             {    printf("%s\n", "fail");                  printf("%s\n", line);                    printf("%s\n", msg);                            }          } 

there times when program print fail, line , msg msg substring of line.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -