Need help with C... stdin and stdout program

Discussion in 'OT Technology' started by suprropmp, Feb 2, 2006.

  1. suprropmp

    suprropmp New Member

    Joined:
    Nov 28, 2004
    Messages:
    5,326
    Likes Received:
    0
    Location:
    Los Angeles
    I've never worked with C before and I now find myself taking a unix and C class. Anyway the second lab we have to do is write a program which copies stdin to stdout with line numbers added. Basically run the program on a file and have it print out all the lines of that file with line numbers.



    I have no clue where to start, can somebody point me in the right direction?
     
  2. RyanL

    RyanL OT Supporter

    Joined:
    Nov 30, 2004
    Messages:
    4,584
    Likes Received:
    0
    Location:
    St. Paul, MN
    You need to write a program that loops through each line of the file, stdin, and then outputs it, using stdout.
     
  3. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    #include <stdio.h>

    int main() {

    return 0;

    }

    thats a start
     
  4. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    you have an input file that you will read from
    before you can read the file you need to open it
    you have to keep track of the number of lines so you need a variable to count them
    once it's open you want to read one line at a time
    read it into a c string
    once you read it you have to write it out to a file
    that file needs to be open to write to it
    once you open it
    you want to write out the number then a space followed by the string you read in
    once the end of file is reached you will close both the input and output files
    and exit

    I will not code this for you post up when you make progress.


    while...there is still
     
  5. suprropmp

    suprropmp New Member

    Joined:
    Nov 28, 2004
    Messages:
    5,326
    Likes Received:
    0
    Location:
    Los Angeles

    ok I'll give it a shot... C cant be any harder than java


    thanks for the help
     
  6. ChosenGSR

    ChosenGSR Mama always said you'd be the chosen one

    Joined:
    Oct 24, 2001
    Messages:
    50,982
    Likes Received:
    214
    Location:
    HoCo, MD
    thats about the dumbest thing i've ever heard. Please tell me you are not comp sci major. Maybe IFSM or something :mamoru: Java is OOP in nature, C isn't. They are not even related.
     
  7. Jadix

    Jadix The Nice Guy

    Joined:
    Jan 19, 2006
    Messages:
    7,877
    Likes Received:
    0
    Java is actually regarded as one of the easiest languages to learn. :-/
     
  8. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    That's complete fucking bullshit. Sure, it's easy to write a hello world in, and it's easy to write the GUI version of hello world, but to do the simplest fucking trivial thing (like read from stdin) takes way more lines of code than it should.

    The fact that Java is taught as a first language is a travesty. Something procedural should be taught first. Once you know that, you can introduce OO concepts and teach people to use Java the way it was meant to be used.
     
  9. suprropmp

    suprropmp New Member

    Joined:
    Nov 28, 2004
    Messages:
    5,326
    Likes Received:
    0
    Location:
    Los Angeles

    easy fucknut, I meant in terms of the learning curve I heard C wasn't too hard.. and yes, I am comp sci

    antiyou: thanks for the help, I just finished the program up :)
     
  10. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,206
    Likes Received:
    517
    :ugh:

    Next, explain why you had to be a dick to post this absolutely useless response. Sometimes I really wish I was a mod in this forum.
     
  11. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    :bigthumb:
     
  12. blang

    blang lang

    Joined:
    Jun 25, 2004
    Messages:
    1,956
    Likes Received:
    0
    Location:
    cambodia
    java is not the easiest language out there.

    i still believe a student's first language should be pascal.

    good structure, easy syntax, procedural
     
  13. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Pascal is an excellent first language.

    It was my first language, back in the day :eek3:
     
  14. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    When I went to college, I was in the last class of students to learn Pascal in the intro to programming classes. The year after me they switched to C++ for the intro classes. I still believe Pascal should be the first language colleges teach because it was originally designed to be a teaching language and it does that very well.
     
  15. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    I learned basic first. I was the last of my class in college to learn c as an intro lang, now it's java :greddy:
     
  16. StevesVR4

    StevesVR4 Get Arrested

    Joined:
    Jul 1, 2003
    Messages:
    7,328
    Likes Received:
    0
    I taught myself basic back in elementary school, but I don't count it as a true language. :mamoru:
     
  17. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
    I actually taught myself pascal I still use it as a scripting language here at work :eek3:
     

Share This Page