Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22004

Why the same code is giving such different output in windows and linux [closed]

$
0
0

Here I am trying to match a string taken from user with the data present in a file. When I type Aditya828 in the required field, it matches with the same present in a file while linux doesnt match it. What is the reason for such a behaviour and how to resolve this? Is there a way I can accomplish my objectiv

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>int main(){        FILE *fp2;        fp2=fopen("StudentId.txt","r");         if(fp2==NULL){         printf("NULL");}        int Nl = 0,var2=-1;        char line[1024],input[255];        while( fgets(line,1023,fp2) != NULL)        {                Nl++;        }        rewind(fp2);        char id[50];        printf("Enter your UserId:\t");        fgets(id,49,stdin);        fgets(id,sizeof(id),stdin);        fgets(input,sizeof(input),fp2);        int cmp;        input[strcspn(input, "\n")] = '\0';        id[strcspn(id, "\n")] = '\0';        for(int z=0; z<Nl; z++)        {                cmp=strcmp(input,id);                if(cmp==1 || cmp==-1)                {                        cmp=9;                }                if(cmp==0)                {                        var2=z;                        cmp++;                        break;                }                fgets(input, sizeof(input), fp2);                printf("%d\n %d\n",var2,cmp );                input[strcspn(input, "\n")] = '\0';        }        printf("<%s>\n<%s>\n",input,id );        printf("%d\n %d\n",var2,cmp );fclose(fp2);}

The content in the StudentId.txt:-

Aditya828Alpha1234vig7819146.8k

the output in windows using mingw compiler:-

Enter your UserId:      Aditya828Aditya828_Aditya828_<Aditya828><Aditya828>0 1

While the output in linux gcc command line:-

Enter your UserId:      Aditya828Aditya828_Aditya828_-1 13-1 8-1 53-1 -16>146.8k<Aditya828>-1 -16

Viewing all articles
Browse latest Browse all 22004

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>