0

Suppose if I have a dynArr pointer and a file pointer as parameters, and in the DynArr I am storing a TYPE with an integer value and a string description. How would I put the TYPEs in the DynArr into a txt file while tabbing between the string and the integer and creating a new line between each TYPE? This is what I have so far:

void write(DynArr arr, FILE *fp)
{	TYPE temp;
	int i;

	for(i = 0; i < (arr->size); i++){


		temp = arr[[i];

		fputc(((&temp)->number, filePtr);
		fputc('/t', filePtr);

		fputs(((&temp)->descrip), filePtr);

   			fputc(('/n', filePtr);    

	}
}

Unfortunately, the integer is not apparent.

I think my main problem is my unfamiliarity with fput.

Thanks in advance.

EDIT: Formatting

Edited by chained: Debugged some problems

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by chained
0

fputc writes a single character to the specified string. If you want to convert an integer to a string and then write it to your file, fprintf would be the easiest:

fprintf(fp, "%d\t%s\n", temp.number, temp.description);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.