I am currently in the process of writing a random poetry generator and have come up against some problems for which I cannot find a solution. My main problem is being unable to assign a string from an array of strings, followed by returning this value and assigning it to another variable for display. I am currently recieving the following errors:
- 50 incompatible types in assignment
- 51 [Warning] return makes integer from pointer without a cast
- 51 [Warning] function returns address of local variable
- 59 incompatible types in assignment
Here is the code I am using, I apologise for any hideous coding...
EDIT: Apologies for not posting the full code
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> char adjective1[15], adjective2[15], adjective3[15], noun1[20], noun2[20], noun3[20], verb1[15], verb2[15], verb3[15], prep1[50], prep2[50], adverb1[15]; char randomadj[15], randomnoun[20], randomverb[15], randomadv[15], randomprep[50]; FILE *myfile; void initrand() { srand((unsigned)(time(0))); } int randint(int max) { int random = (max*rand()/(RAND_MAX+1.0)); return (random); } char randadj() { char string[15]; char stringOut[15]; myfile = fopen("adjective.txt", "r"); int endval = 0; while ((string, 15, myfile) != NULL) { endval++; } return endval; int i; char array[endval][50]; for (i = 0; i<=endval-1; i++) { fgets(string, 15, myfile); int len = strlen(string) - 1; if (string[len] == '\n') string[len] = '\0'; int j; for (j = 0; j<=len; j++) { array[i][j] = string[j]; } } int randnum = 0; randnum = randint(endval-1); stringOut = array[randnum]; return stringOut; } int main(int argc, char *argv[]) { initrand(); randomadj = randadj; strcpy(adjective1, randomadj); strcpy(adjective2, "feeding"); strcpy(adjective3, "flawless"); strcpy(noun1, "Book"); strcpy(noun2, "tongue"); strcpy(noun3, "mountain"); strcpy(verb1, "shines"); strcpy(verb2, "drools"); strcpy(verb3, "regurgitates"); strcpy(prep1, "in harmony with"); strcpy(prep2, "without thinking about"); strcpy(adverb1, "feeding"); printf (" A %s %s", adjective1, noun1); printf ("\n------------------------------------------------------"); printf ("\n A %s %s %s %s the %s %s.", adjective1, noun1, verb1, prep1, adjective2, noun2); printf ("\n While %s the %s %s.", adverb1, noun1, verb2); printf ("\n The %s %s %s a %s %s.\n", noun2, verb3, prep2, adjective3, noun3); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks



