Manipulating Text Files In C!

This is a discussion on Manipulating Text Files In C! within the C Programming forums, part of the General Programming Boards category; Hello everyone!!!As this is my first post I'll try to be quick and not frustrating!! I have some playlists and ...

  1. #1
    Registered User lordi's Avatar
    Join Date
    Nov 2006
    Posts
    3

    Manipulating Text Files In C!

    Hello everyone!!!As this is my first post I'll try to be quick and not frustrating!!
    I have some playlists and I just want to open them as text and change the first letter on each line (only if it is not a #) to whatever I want!!A few functions and how they work would be great!!Thanx a lot in advance and Thanx again and again!Thaaaaaaaaaaaaaaanx!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Less ! helps.

    In the meantime, read up on fopen(), fgets() and fclose()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User lordi's Avatar
    Join Date
    Nov 2006
    Posts
    3
    yes but how can I change line every time I read the first letter?!With fgetc i can read a letter but the next I'm going to read is not from the other line but next to the first one!

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You're not trying very hard -- this discourages folks from helping.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       static const char filename[] = "file.txt";
       FILE *file = fopen(filename, "r");
       if ( file != NULL )
       {
          char line[BUFSIZ];
          while ( fgets(line, sizeof line, file) != NULL )
          {
             printf("first character on the line: '%c'\n", line[0]);
          }
          fclose(file);
       }
       else
       {
          perror(filename);
       }
       return 0;
    }
    
    /* my output
    first character on the line: 'M'
    first character on the line: 'J'
    first character on the line: 'J'
    first character on the line: 'T'
    first character on the line: 'B'
    first character on the line: 'M'
    */
    Help us help you by posting your attempt.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User lordi's Avatar
    Join Date
    Nov 2006
    Posts
    3
    you're right!!Sorry!thanx for helping though!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-11-2008, 12:36 AM
  2. text files in c++
    By DungeonMaster in forum C++ Programming
    Replies: 5
    Last Post: 03-14-2006, 02:48 PM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. text files & notepad problem
    By bigtamscot in forum C Programming
    Replies: 2
    Last Post: 05-01-2003, 04:41 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21