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

Could you at least post code which will compile?
Also please post the defintions of TYPE and DynArr.

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);

Thank you! That fixed the integer problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.