Need help assignment

This is a discussion on Need help assignment within the C Programming forums, part of the General Programming Boards category; Ok I've managed to make it work through sweat and tears and pure determination I've written a total of 27 ...

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    Ok I've managed to make it work through sweat and tears and pure determination I've written a total of 27 if/if else's.

    Now I still can't get the numbers and spaces to work, any ideas?

    I updated the code FYI.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    For the numbers, setting output to 7 does not mean you will display '7', since 7 is <beep>.

  3. #18
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    the var simply tells it when to stop

    it scans twice once to keep the loop going, the other for the program

    ok so what do I do about the numbers? I tried to use fscan for variables for the digits 0-9 and got a segmentation fault

    how do i scan single digits?
    Last edited by 6kaine9; 10-19-2008 at 08:56 PM.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by 6kaine9 View Post
    the var simply tells it when to stop

    it scans twice once to keep the loop going, the other for the program
    You may have deluded yourself into thinking so, but that's simply not true. Print out chrr and var before you start encrypting and see for yourself.
    Quote Originally Posted by 6kaine9 View Post
    ok so what do I do about the numbers? I tried to use fscan for variables for the digits 0-9 and got a segmentation fault

    how do i scan single digits?
    Edit: You had that right the first time. Now you've got the logic right, you just have to not use this var thing.
    Last edited by tabstop; 10-19-2008 at 09:04 PM.

  5. #20
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    But I've already used the program for encrypting. It *IS* working its just that the spacebars and numbers don't work.

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you won't print out var, I will:
    Code:
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 0
    var is: 102378
    where oh where could your numbers have gone. (Note this is also where your spaces have gone.)

  7. #22
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    lmao ok you're right I just printed it too.

    I bow down to your greatness.

    So now what, toss it?

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to do the same reading in the loop that you did outside, or used to:
    Code:
    var = fscanf("&#37;c", &chrr);
    Remember fscanf returns EOF on trying to read end of file. And also that read has to be inside the while loop, as in
    Code:
    while ((var = fscanf("%c",&chrr)) != EOF)
    And actually you don't really need var:
    Code:
    while (fscanf("%c", &chrr) != EOF)

  9. #24
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    ok i replaced that bit of code now it's telling me

    encrypt10.c:27: warning: passing arg 1 of `fscanf' from incompatible pointer type

  10. #25
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Oops, forgot the filename. You'll need f_in as the first parameter.

  11. #26
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    abcdef uvwxyz ZYXWVUTS RQPONML 102378

    ok this bit is what it's supposed to read

    I run it and input 0 as k, and it outputs:

    abcde
    It's stopping at the spacebar, why?

  12. #27
    Registered User
    Join Date
    Oct 2008
    Posts
    15
    lmao I had a break after the "else" bit of code.

    Thanks so much man you don't believe how much of a help you were.

    Now to decrypt the code....lmao

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

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 07:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 02:21 PM

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