Using strcmp, char variable changes value?
Ok, so I'm relatively new to this whole programming thing, but I have written a few programs before. I use Dev C++ as my IDE, running XP. In FreeBSD, I use gcc to compile and vim to write.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
int main (void)
{
char a[21];
char b[21];
char c[99];
int d;
FILE *syns;
FILE *thes;
FILE *alp;
syns = fopen ( "syns", "r");
thes = fopen ( "thes", "r");
alp = fopen ( "alp", "w");
fseek( syns, 0L, SEEK_SET );
while(1==fscanf(syns,"%s",a)) /*While there are words, take a word from the list*/
{fseek( thes, 0L, SEEK_SET);/*go to beginning of thesaurus*/
while(1==fscanf(thes,"%s",b)) /*While there are words in thesaurus, take one and...*/
{
if (!strcmp(a,b)) /*...Compare it to the word from the list. If they are the same,*/
{
fprintf(alp,"%s- ",a);/*Print the word*/
for(d=0;d<=15;d++)/*Pick amount of synonyms*/
{
fscanf(thes,"%s",c); /*take current word*/
fprintf(alp,"%s, ",c);/*print it*/
}
fprintf(alp,"\n");/*Goto a newline when finished*/
}
}
}
return (0);
}
Input file (syns) contains the word 'hi'. thes is a thesaurus. Output file, alp, contains only "t- true_to_form, true_to_type, typal, typic, typical, unblamable, unexceptionable, usual, virtuous, warning, well-deserving, worthy, exemplification, allegorization, alphabet, art, "
yeah, I know i should use malloc and other fun stuff. Right now I just want it to work.