Trouble with a lab

This is a discussion on Trouble with a lab within the C Programming forums, part of the General Programming Boards category; It really depends on what all your fomatting rules are. I don't understand exactly how you know when you are ...

  1. #16
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    It really depends on what all your fomatting rules are.

    I don't understand exactly how you know when you are missing a month.
    Sometimes there are 2 spaces between two values sometimes 3.

    If 2 spaces means you are missing one month what does 3 spaces mean?

    Anyway, I would step through character by character and decide what you need to do. Of course you'll have to modify this fit your rules

    Code:
        while( (fscanf( input, "%c", &holder ) != EOF) )
        {
            if(holder == ',')  //replace comma with tab
            {
                fprintf( output, "%c", '\t' );
                prev_holder = holder;
            }
            else if(prev_holder == ' ' && holder == ' ')  // two consecutive spaces, replace 2nd with asterick
            {
                fprintf( output, "%c", '*' );
                prev_holder = '*';
                //if 3 spaces means missing 2 months, which I'm guessing it does, this instead
                //fprintf( output, "%s", "* " );
                //prev_holder = holder; //can be moved outside if statments since always the same
            }
            else
            {
                fprintf( output, "%c", holder );  //just print the character
                prev_holder = holder;
            }
        }
    Last edited by spydoor; 12-06-2005 at 04:44 PM.

  2. #17
    null
    Join Date
    Dec 2005
    Posts
    18
    spydoor, I agree with you entirely. The way the input file was given to me, with all these jumbled up spaces and with a poor description, was confusing at best.

    What you provided is a great solution. Thank you for that. I was overlooking the fact that char printing will print each number of the float, so I didn't need to worry about printing the whole float at once.

    I've got a final question, and this is more for my understanding of what you showed me. In the else if statement, using "%s" and then double-quotes (instead of singles) around the asterik... what is that? I was only aware of %d, %c, and %f and their modifiers.

  3. #18
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    single quotes are used for single characters

    double quotes are used for a string of characters.
    %s is the modifier for strings.

    In this case I did asterick followed by space. Since it is more than one character, double quotes and %s were required.

    If you'd rather not use %s you can always do to two calls to fprintf
    Code:
    fprintf( output, "%c", '*' );
    fprintf( output, "%c", ' ' );
    Once again I'm making assumptions about the formatting you need. Just guessing you'd want a space after each asterick.

  4. #19
    null
    Join Date
    Dec 2005
    Posts
    18
    Thanks spydoor, that was the formatting I needed. And thanks to everyone else who added their input. I learned more with this one than any of the other labs.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 11:44 AM
  2. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  3. Datastructure lab
    By El_Maco in forum C++ Programming
    Replies: 14
    Last Post: 10-10-2004, 08:35 AM
  4. programming from home to the lab???
    By nbo10 in forum Tech Board
    Replies: 7
    Last Post: 08-27-2004, 05:35 PM
  5. Please help debug this lab! Please!
    By mack_ol in forum C Programming
    Replies: 0
    Last Post: 02-17-2002, 12:32 PM

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