Results 1 to 4 of 4

Thread: Writing from a certain line in C

  1. #1
    Join Date
    May 2008
    Posts
    13

    Writing from a certain line in C

    I have the following code, but even more is an algorithm but it is the final pint take more or less.
    Code:
    void function (char * insert) ( 
      Fila * copy; 
      Long a; 
    
      assert (copy = fopen ( "copia.txt", "aw")); 
    
      fseek (copy, 0, SEEK_CUR); 
      = ftell (copy); 
    
      fprintf (stdout, "I'm in character% d \ n", a); 
    
      fputs (insert copy); 
      fputs ( "\ n", copy); 
    
      fclose (copy); 
      ) 
    
    
      Main (void) ( 
    
      char * [4] = ( "Hello", "Gold", "americas", "Eloisa"); 
      int b; 
      char c [100]; 
      char * d; 
      char insertion [20]; 
      Fila * file; 
    
      if (! (file = fopen ( "file.txt", "r"))) ( 
      fprintf (stdout, "Error opening \ n"); 
      clearerr (file); 
      ) 
    
      fgets (c, 50, file); 
      d = strtok (c, ""); 
    
      while (d! = NULL) ( 
    
      for (b = 0; b <4 b + +) ( 
      if (strcmp ([b] d) == 0) ( 
    
      fprintf (stdout, "% s% = s are equal \ n", [b] d); 
      fprintf (stdout, "Inserts word to enter \ n"); 
      fscanf (stdin, "% s", & integration); 
      fprintf (stdout, "Thanks Wait .... \ n"); 
      function (integration); 
      system ( "sleep 02"); 
    
      Else () 
      fprintf (stdout, "% s% = s are not equal \ n", [b] d); 
      ) 
    
      ) 
      break; 
      ) 
    
      fclose (file); 
      return 0; 
      )
    What I want is that the function which opens a file called 'copia.txt' for writing, there is some way to use fgets provided for positions after 11 characters and write from there and not just from the end (Seek_end) or the start (SEEK_SET) and could put the arrow after 11 characters and write there: /

  2. #2
    Join Date
    Apr 2008
    Posts
    3,522
    if I am not mistaken,
    Code:
    fseek (copy, 11L, SEEK_SET);

  3. #3
    Join Date
    Apr 2008
    Posts
    3,267
    Quote Originally Posted by strangist View Post
    What I want is that the function which opens a file called 'copia.txt' for writing, there is some way to use fgets provided for positions after 11 characters and write from there and not just from the end (Seek_end) or the start (SEEK_SET) and could put the arrow after 11 characters and write there: /
    int fseek (IBF * stream, long int offset, int origin);

    Parameters
    Stream
    Pointer to a file object that identifies the stream.
    Offset
    Number of bytes to offset from origin.
    Origin
    Position from where offset is added. It is specified by one of the following constants defined in <cstdio>:
    SEEK_SET Beginning of File
    SEEK_CUR Current position of the file pointer
    SEEK_END End of File
    Code:
    fseek (copy, 11, SEEK_CUR);
    Obviously in your original code (not what I will certainly come to appreciate) fseek does nothing for it asking that these moves 0 bytes from the current position. We can also use perfectly SEEK_SET and which is more logical in this case but not what we demand.

  4. #4
    Join Date
    May 2008
    Posts
    13
    fseek (File, 10, seek_cur);

    I have tried this in various ways. Even tested on instead uploaded -10 for example, and indeed according to the printf is located in that line, but when I write command to strip by the end of the text (I assume that by append) but if I 'write' I delete everything and I overwrites the text: / (write clear is supposed to work that way).

    I had already tested line position as the two of you expressed here, and they seem not lie Quiz probe suggest that in this way when you start the post modify the code until before Posten, for which I was not riddled by saying that what I was doing was a stupidity ... as has happened on other occasions ... and that more rounds for the code actually works and does not give me an answer to because it works but is evil and is now in order ...

    That exposes what had already done previously, does not work independently that the pointer is placed at x line does not write me from there, I wrote at the end (if I use append) or at home (write )....

    Then looking into this situation, the problem really is not that I know of that position because I am aware that there is the problem here is append and write, there is some form or some function that allows me to write from that line, porke append and are helping not write much .....

    Incidentally, while not actually going in the code that does not quiz post here to avoid insults superiors, took a if ... with sufficient for it.

Similar Threads

  1. dvd writer is not writing dvd
    By Sumit5342469 in forum Hardware Peripherals
    Replies: 3
    Last Post: 03-10-2011, 01:26 AM
  2. best software for cd/dvd writing
    By skpanda in forum Windows Software
    Replies: 1
    Last Post: 28-10-2010, 06:39 AM
  3. How to let Java read text file line by line.
    By Visala28 in forum Software Development
    Replies: 3
    Last Post: 04-08-2009, 11:30 PM
  4. How can i reduce the writing speed of a DVD
    By Dolf in forum Hardware Peripherals
    Replies: 2
    Last Post: 06-02-2009, 01:07 PM
  5. DVD Writing Software
    By Crona in forum Windows Software
    Replies: 4
    Last Post: 24-12-2008, 06:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,589,406.40927 seconds with 16 queries