c - Returning a pointer of string arrays from a function -
So I need help returning an indicator of string arrays from the function obtained from a file. The wire is not bigger than 10.
Input file:
3 102 a3b 50
The first number is the wire I need, the following numbers give me the stars Are required to be stored in.
Function:
char ** buildArray () {int x, i; Fscanf (FP, "% d", and;); Four answers [x] [10]; For (i = 0; i
I can get the values stored correctly on the string array 'Answer', I can not return it correctly.
Main Function:
int main () {char * answers; Fp = fopen ("data.txt", "r"); If (fp == NULL) {printf ("The file was not found. \ N"); Exhaust (EXIT_FAILURE); Answer = BuildAnsure (); Printf ("% s", answer [1]); // is used as a test to see if I have correctly fckose the array of stars; Return 0; }
When I try and value a value in the main function, it crashes, or touches strange symbols
Assuming there is some taste of C, you are trying to return an indicator to a variable, answer
, Which was automatically allocated within a function, which means when you exit the function, it will automatically Distributed , then either create this answer
outside this function and pass it to fill it, or assign space for it so that the function is live after return.
Comments
Post a Comment