Hi, I'm currently trying to store a string by using this notation: prvstring[STRSIZE] = str[STRSIZE]. For some reason it doesn't work. Is there a way to assign a variable equal to a string? Thank you very much!
Code:#include<stdio.h> #include<string.h> int main(void) { #define STRSIZE 20 FILE *pf; char str[STRSIZE]; /*Maximum size of a string is 20*/ char ustring[STRSIZE]; char *chpoint; char prvstring[STRSIZE]; pf = fopen("input.txt","r"); if (!pf) { printf("Can't open the file\n"); return 0; } printf("Enter a string. "); chpoint = strchr(ustring, '\n'); /*searches for "\n", address is returned if found; otherwise NULL is returned*/ if (chpoint != NULL) { *chpoint = 0; /*removes the \n*/ } while (fscanf(pf, "%s",str) == 1) /*continue to scan and print strings until the EOF*/ { int v = strcmp (ustring, str); if (v == 0) { printf ("<%s> equals <%s>.\n", ustring, str); } printf("previous string is: %s \n", str); prvstring[STRSIZE] = str[STRSIZE]; printf("new string is: %s\n", prvstring[STRSIZE]); } fclose(pf); /*close file*/ return 0; }



LinkBack URL
About LinkBacks



