473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Inserting lines when copying file.

64
Hello, I am trying to write a code to copy a file which I can do as you can see below.

Expand|Select|Wrap|Line Numbers
  1. void  copy  ()
  2. {
  3. //    Local Definitions 
  4.     int c;
  5.     int closeStatus;
  6.     FILE* spProverbs ;
  7.     FILE* spProverbsCopy;
  8. //    Statements 
  9.      printf("Begin file copy\n");
  10.  
  11.     if (!(spProverbs = fopen ("Proverbs.TXT", "r")))
  12.         {
  13.          printf("Error opening Proverbs.TXT for reading");
  14.          exit (101);
  15.         } // if open input  
  16.     if (!(spProverbsCopy = fopen ("ProverbsCopy.TXT", "w")))
  17.         {
  18.          printf("Error opening ProverbsCopy for writing");
  19.          exit(201);
  20.         } // if open output 
  21.  
  22.         while ((c = fgetc(spProverbs)) != EOF)
  23.         fputc(c, spProverbsCopy);
  24.  
  25.     fclose(spProverbs);
  26.     closeStatus = fclose(spProverbsCopy);
  27.     if (closeStatus == EOF)
  28.        {
  29.         printf("File close error.\a\n");
  30.         exit(200);
  31.        } // if close error 
  32.     printf("File successfully created\n");
  33.  
  34.     return;
  35.  
  36. }// copy
  37.  
  38.  
My question is do I insert numbers. Let me do an example

Expand|Select|Wrap|Line Numbers
  1. PROVERBS.TXT 
  2.  
  3. Between the devil and the deep sea:  To choose between 
  4. two equally  bad  alternatives in  a  serious  dilemma.
  5.  
  6. Where there's a will there's a way:  When a person 
  7. really wants to  do something,  he will  find a way of 
  8. doing  it.
  9.  
  10. A friend in need is a friend indeed:  A friend 
  11. who  helps when one is in  trouble is a real friend.
  12.  
  13. Discretion is the better part of valor:  If you say
  14. discretion is the better part of valor,  you  mean 
  15. that avoiding a dangerous or   unpleasant situation 
  16. is   sometimes the most  sensible thing to do.
  17.  
  18. Great talkers are little doers: Those people who 
  19. talk a lot and are always  teaching others usually 
  20. do   not   do   much   work.
  21.  
  22.  
  23. Text after processing:
  24.  
  25.  1. Between the devil and the deep sea:  To choose between 
  26.  2. two equally  bad  alternatives in  a  serious  dilemma.
  27.  3. 
  28.  4. Where there's a will there's a way:  When a person 
  29.  5. really wants to  do something,  he will  find a way of    
  30.  6. doing  it.
  31.  7. 
  32.  8. A friend in need is a friend indeed:  A friend 
  33.  9. who  helps when one is in  trouble is a real friend.
  34. 10.
  35. 11. Discretion is the better part of valor:  If you say 
  36. 12. discretion is the better part of valor,  you  mean 
  37. 13. that avoiding a dangerous or   unpleasant situation 
  38. 14. is   sometimes the most  sensible thing to do.
  39. 15.
  40. 16. Great talkers are little doers: Those people who 
  41. 17. talk a lot and are always  teaching others usually 
  42. 18. do   not   do   much   work.
  43.  
  44.  
I can copy the file fine, but really have no clue how to insert numbers in the first of each line. If anyone could give me a clue or example that would be great. Thanks in advance.
Mar 9 '07 #1
3 1964
Ganon11
3,652 Expert 2GB
Well, you can check if a character is a newline. If it is, after you output it to the copied file, you can output a number plus ".)". You will have to keep track of how many lines you have printed with a variable - starting at 2 (do you know why?). Also, you will have to manually output "1.)" to the file before anything else is output.
Mar 9 '07 #2
td0g03
64
Well, you can check if a character is a newline. If it is, after you output it to the copied file, you can output a number plus ".)". You will have to keep track of how many lines you have printed with a variable - starting at 2 (do you know why?). Also, you will have to manually output "1.)" to the file before anything else is output.
Hello, I'm sorta comfused. Anyway you could provide me with an example? Thanks again.

new line would "c == \n" that would tell me if it would be a new line or not? Sorry, I'm really confused on this problem. Been stuck on it for a few hours now.
Mar 9 '07 #3
Ganon11
3,652 Expert 2GB
Well, c == '\n' rather than c == \n, but yes, that would tell you if the character was a newline character.
Mar 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: news | last post by:
I'm building an e-commerce site, where the owner needs to be able to upload a CSV file of product that gets inserted into mySQL. Unfortunately, I think my Web host may have some functions turned...
5
by: Peter Nagel | last post by:
I would like to insert some strings in a multiline TextBox. At the time of inserting the TextBox already contains some strings each in a separate line. The new lines should be inserted somewhere in...
1
by: Robert Halstead | last post by:
Hi guys, I am copying text from Microsoft Word 2003 into a asp.net text box then writing the textbox to a file. My problem is, when I go to display the file using regular asp, it get all these...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
23
by: r.e.s. | last post by:
I have a million-line text file with 100 characters per line, and simply need to determine how many of the lines are distinct. On my PC, this little program just goes to never-never land: def...
1
by: Sai Krishna M | last post by:
I want to insert a string in a file after a particular line. I thought of using seek() function but on opening the file in append mode the seek value is undone. One crude idea i had was to read...
4
by: Zenon | last post by:
I have been tasked with writing code which overrides the TraceListener class for the purpose of limiting the size of the log file. Basically, when the log file grows to a certain size, I need to...
0
by: Edwin.Madari | last post by:
-----Original Message----- statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/ inline statemets can be exeucuted only. hope that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.