Question
C Programming

23 points Write a function for the following specs: type: void parameters: FILE, int[], int size • Behavior: Write the text
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C Code:-

#include<stdio.h>
// Function with void type to insert all array element into the file
// Each value in single line.

void text_to_file(FILE *f,int a[],int n)
{
// Open the File in write mode.
f=fopen("file1.txt","w");
  
// Writing in the File
for(int i=0;i<n;i++)
fprintf(f,"%d\n",a[i]);
  
// Closing the File.
fclose(f);
printf("Content Succesfully copied to file.\n");
}
int main()
{
// Array with some elements
int a[]={1,3,6,8,5,3,4,7,9};
  
// Calculating the size of an array.
int n=sizeof(a)/sizeof(a[0]);
  
// File pointer declared as f
FILE *f;
  
// Calling the function to insert the array number into file.
text_to_file(f,a,n);
return 0;
}

*** main.c file1.txt 1 #include<stdio.h> 2 \/ Function with void type to insert all array element into the file 3 // Each val

Text FIle:-

. file 1.txt main.c 1 1 2 3 3 6 4 8 5 5 6 3 7 4 8 7 9 9

Add a comment
Know the answer?
Add Answer to:
C Programming 23 points Write a function for the following specs: type: void parameters: FILE", int[],...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT