Hi Guys,
I wonder if someone can help me out with this. I'm running the same C code in diffferent platforms (windows/unix) but getting different result. For instance the code is:
fgets(line,LINE_BUF,fp);
while (!feof(fp)) {
Len=strlen(line) - 1;
if ( (newNode=malloc(sizeof(ListNode))) == NULL)
{
fprintf(stderr,"\nListInsert: Memory Allocation failed! Aborting.\n");
break;
}
current = head;
previous = NULL;
/* Search to find where in insert new list node */
while (current != NULL )
{
previous = current;
current = current->next;
}
if ( Len > 0) {
strncpy(newNode->word,line,Len);
}
newNode->next = current;
fgets(line,LINE_BUF,fp);
if (previous == NULL)
{
head = newNode;
}
else
{
previous->next = newNode;
}
}
Basically what I'm trying to do is load a linklist but for example here is the output of the program executed from Unix:
written Len: 7 Number : 3917
wrong Len: 5 Number : 3918
wrote Len: 5 Number : 3919
year Len: 4 Number : 3920
years Len: 5 Number : 3921
yellow Len: 6 Number : 3922
yes Len: 3 Number : 3923
yesterday Len: 9 Number : 3924
yet Len: 3 Number : 3925
you Len: 3 Number : 3926
young Len: 5 Number : 3927
your Len: 4 Number : 3928
yours Len: 5 Number : 3929
yourself Len: 8 Number : 3930
zero Len: 4 Number : 3931
And here is the output of the same program executed on Windows:
written Len: 7 Number : 3917
wrong☺= Len: 7 Number : 3918
wrote☺= Len: 7 Number : 3919
yearx☺= Len: 7 Number : 3920
years☺= Len: 7 Number : 3921
yellow= Len: 7 Number : 3922
yes Len: 3 Number : 3923
yesterday Len: 9 Number : 3924
yet Len: 3 Number : 3925
you Len: 3 Number : 3926
young☺= Len: 7 Number : 3927
your­♦= Len: 7 Number : 3928
yours♦= Len: 7 Number : 3929
yourself Len: 8 Number : 3930
zero°☻= Len: 7 Number : 3931
Just in case the print statement is the same in both platforms and it looks like this :
printf("%s Len: %d Number : %d\n", current->word,Len1,count);
Please any help on what should I do to overcome this problem would be highly appreciated. thanks.
harby