Question

Write a function that will add a new record to the end of the csv file....

Write a function that will add a new record to the end of the csv file. The signature of
the function will be:
void add_record(const char* csv_filename, const char* name, const int age, const
char* city);

format of the csv file is ;

Jake, 25, Montreal
Maria, 34, Wawa
Desmond, 19, Head-Smashed-In-Buffalo-Jump
Ali, 42, Bangor
Maria, 29, Saint-Louis-du-Ha-Ha

0 0
Add a comment Improve this question Transcribed image text
Answer #1

void add_record(const char* csv_filename, const char* name, const int age, const
char* city) {

File *file = fopen(csv_filename, "a"); //Opening the file with append mode

if(file == NULL) {

printf("Error in opening file");

} else {

fputs(name, file);

fputs(",", file);

fputs(age, file);

fputs(",", file);

fputs(city, file);

fputs("\n", file);

} //Writing data in comma spearated format

}

Please comment in case of any doubts.

Add a comment
Know the answer?
Add Answer to:
Write a function that will add a new record to the end of the csv file....
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
  • According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses...

    According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. A CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A company has text data that is not...

  • Requirements Print a range Write a bag member function with two parameters. The two parameters are...

    Requirements Print a range Write a bag member function with two parameters. The two parameters are Items x and y. The function should write to the console all Items in the bag that are between the first occurrence of x and the first occurrence of y. You may assume that items can be compared for equality using ==. Use the following header for the function: void print_value_range(const Item& x, const Item& y); print_value_range can be interpreted in a number of...

  • Write a C++ program with a function to read in the file parts.txt into either parallel...

    Write a C++ program with a function to read in the file parts.txt into either parallel vectors or a vector of structs. The data file is on ANGEL in zipped format. The first few lines of the file look like: P-13725 A 23 61.46 P-13726 B 12 51.08 P-13754 D 27 4.56 P-13947 C 34 27.71 Representing part number, Class, On hand balance, cost. After the vector(s) has/have been filled, display a menu which allows the user to request the...

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