Thread: New to C, tried first program, Need help

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    2

    Question New to C, tried first program, Need help

    Hey everybody! Well i want to learn how to program and do other things with computers because i think it will be useful with technology becoming greater every day.

    Well i checked out c programming on howstuffworks.com and i'm already stuck on the first page

    The problem is when i type the program into the command prompt.

    The message reads "no such file or directory"

    I already downloaded DJGPP and did what the installation asked on delorie.com but it still won't work. This is my first hurdle i would really appreciate it if you guys can help me overcome it! Thanks in advance.

    here is the website to the program and what they are saying to do.

    http://computer.howstuffworks.com/c2.htm

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    First of all, I would ditch DJGPP since it's a ye olde DOS compiler, although it's 32-bit. What you really want is a Windows compiler. I would recommend getting MinGW, which is a Windows port of GCC. If you want a more easy installation, then LCC might be easier. They are both free, and they both can write console and Win-32 programs.

    With regard to howstuffworks.com's tutorial on C, I would say the diagrams are very good and some explanations are really nice for someone starting out. In terms of the code, however, they write a lot of code that is incorrect and you should be aware of. Take the code examples with a grain of salt.

  3. #3
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Dev-C++ is a nice IDE
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    The problem is when i type the program into the command prompt.
    the program you made or the compiler program?

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Are you in the right directory?
    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.

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    2
    So it seems like i should use a different complier instead of DJGPP?

    And i mean the program i created not the compiler itself. the one that HowStuffWorks.com says to save as samp.c

    And i'm not sure if i'm in the right directory and i don't know how to change the directory so i think i need help with that. Currently the prompt says that i'm in

    C:\Documents and Settings\Khang>

    I tried saving the samp.c into the same files but still it doesn't show up, or maybe i'm typing the thing wrong?

    i'm typing gcc samp.c-o samp.exe

    the samp.c is followed by a dash and then the letter o not zero.

    Still doesn't show up, please help.

    Thanks

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    type
    dir
    and
    gcc -v
    what does it say?

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    To use gcc, you must have either MinGW or cygwin installed on Windows, or be using a version of Unix or Linux.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    khangaroo, just saying "it doesn't work" is NOT helpful. Post what you typed in (which you already did, very good there), and what the command prompt yells back at you.

    Quote Originally Posted by khangaroo View Post
    i'm typing gcc samp.c-o samp.exe

    the samp.c is followed by a dash and then the letter o not zero.
    There should be a space between the source file and the -o option as in so:

    gcc samp.c -o samp.exe

    If gcc is not in your PATH then you will need to use a fully qualified path name, i.e. C:\directory\to\wherever\gcc\is\installed\gcc.exe samp.c -o samp.exe

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can copy what the prompt says exactly by right-clicking on the window, selecting Mark, selecting the text you want to copy, and pressing enter.

    You'll probably get one of these error messages.
    1. Code:
      'gcc' is not recognized as an internal or external command,
      operable program or batch file.
      or, for pre-Windows 2000 versions,
      Code:
      Bad command or file name
      This means that GCC is not in your path.
    2. Code:
      gcc: samp.c: No such file or directory
      gcc: no input files
      or some other error message from GCC. This means that your source file is not in the current directory.

    1. If GCC is not in your path, type
    Code:
    path=c:\path\djgpp\bin;%PATH%
    where path is the location you installed DJGPP.

    Instead of doing that every time, you can add that line to the end of C:\autoexec.bat (assuming that C: is your main drive). You may have to create it -- most XP systems don't have an autoexec.bat. You can use notepad -- type that line above, then save as "\autoexec.bat" -- with the quotes. They prevent .txt from being appended to the end of the filename.

    Then type c:\autoexec.bat from the command line to run it. autoexec.bat is automatically run when the computer starts, so you'll only have to type \autoexec.bat until you reboot. Or you can just reboot immediately.

    2. If you're in the wrong directory, type "cd directory" or "cd .." to go up a directory, until you're in the right place.
    Code:
    C:\temp>cd ..
    
    C:\>cd "Documents and Settings"
    
    C:\Documents and Settings>cd user
    
    C:\Documents and Settings\user>
    Etc.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM