Welcome to the Linux Foundation Forum!

trouble with c

Options

hey, i'm trying to learn c so i wrote a program that doesn't do exactly what i want it to, try as i might i couldn't find the bug so i was hoping you could help me out.

here's the program: http://pastebin.com/1uYraxeM

and here's the input, output, and expected output: http://pastebin.com/7bmEuvP8

any help you could give me i would be very greatful for

Comments

  • asedt
    asedt Posts: 96
    edited April 2012
    Options
    I not so good at C but I think this is the problem:
    You type more than what getchar takes and put in s. the rest needs to be flushed.
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044873249&id=1043284392

    edit: Newer mind this I did read it wrong
    [I not so good at C but obvious line 29 don't do what we want it to do.
    I think the best thing to do is to use the lim value so you newer add to much chars to the s array in the first place.
    Your not getting any out of bounds error messages?]
  • weedlight
    Options
    Please, Tell us what terminal, charset and operating system you are using. Assumed you run it on a different platform than GNU/Linux you should pay attention on different line delimiter(s).

Categories

Upcoming Training