How do I add .C Project to my complier?

This is a discussion on How do I add .C Project to my complier? within the C Programming forums, part of the General Programming Boards category; That is to say, "library" is part of the comment "include information about standard library" that is attached to the ...

  1. #46
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That is to say, "library" is part of the comment "include information about standard library" that is attached to the line #include <stdio.h>

  2. #47
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Will someone please tell me if this example will fail so I can learn, or are they true? I get them to fail.



    Here is a description:


    Most of the work gets done in the body of the loop. The Celsius temperature is computed and
    assigned to the variable celsius by the statement
    celsius = 5 * (fahr-32) / 9;
    The reason for multiplying by 5 and dividing by 9 instead of just multiplying by 5/9 is that in
    C, as in many other languages, integer division truncates: any fractional part is discarded.
    Since 5 and 9 are integers. 5/9 would be truncated to zero and so all the Celsius temperatures
    would be reported as zero.
    This example also shows a bit more of how printf works. printf is a general-purpose
    output formatting function, which we will describe in detail in Chapter 7. Its first argument is
    a string of characters to be printed, with each % indicating where one of the other (second,
    third, ...) arguments is to be substituted, and in what form it is to be printed. For instance, %d
    specifies an integer argument, so the statement


    Quote from the book below:

    Code:
    printf("%d\t%d\n", fahr, celsius);

    My quote below:


    Code:
    #include <stdio.h>
    int main()
    {
    	printf("%d\t\%d\n", fahr, celsius");
    }

  3. #48
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have an extra stray quote sign after celsius. You also seem to be missing the rest of the program (where fahr and celsius are defined, and one is read in, and the other is calculated). This line by itself will not compile.

  4. #49
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Quote Originally Posted by tabstop View Post
    You have an extra stray quote sign after celsius. You also seem to be missing the rest of the program (where fahr and celsius are defined, and one is read in, and the other is calculated). This line by itself will not compile.
    That's it. I give up with this book.

    If someone can't recommend a good book then I give up. Now, back to hello, world. This is exactly what I mean by no int

    This is coming from the book.



    Code:
    #include <stdio.h>
    main()
    {
    printf("hello, ");
    printf("world");
    printf("\n");
    }

  5. #50
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by php111 View Post
    That's it. I give up with this book.

    If someone can't recommend a good book then I give up. Now, back to hello, world. This is exactly what I mean by no int

    This is coming from the book.



    Code:
    #include <stdio.h>
    main()
    {
    printf("hello, ");
    printf("world");
    printf("\n");
    }
    1. As I said, I don't have a copy of the book, but I'm pretty sure I've seen that entire example from the book. It's there in print. But the point is you can't pull out one line of a program and expect it to work without all the rest of the stuff around it. There's not anything any book can do about that.

    2. As for main vs. int main, K&R get a pass, since they wrote the language and they didn't require int main. Now since you are using a C++ compiler (for whatever reason only you know) you're getting in trouble, since C++ closed down that loophole and require int main. If you were compiling a .c file, using C settings you'd get a warning about it but not an error.

  6. #51
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Quote Originally Posted by tabstop View Post
    1. As I said, I don't have a copy of the book, but I'm pretty sure I've seen that entire example from the book. It's there in print. But the point is you can't pull out one line of a program and expect it to work without all the rest of the stuff around it. There's not anything any book can do about that.

    2. As for main vs. int main, K&R get a pass, since they wrote the language and they didn't require int main. Now since you are using a C++ compiler (for whatever reason only you know) you're getting in trouble, since C++ closed down that loophole and require int main. If you were compiling a .c file, using C settings you'd get a warning about it but not an error.


    Oh OK. So, if I want to follow the book then I need a C complier (not C++), right? I was recommended the Visual Studio over AIM. I don't know of any freeware C compliers.

  7. #52
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by php111 View Post
    Oh OK. So, if I want to follow the book then I need a C complier (not C++), right? I was recommended the Visual Studio over AIM. I don't know of any freeware C compliers.
    Visual Studio's compiler has a C compatibility switch you can flip, /Tc (somewhere I forget where). You should be getting that automatically if your file ends with .c instead of .cpp. (The easy way to check is to get into Windows and browse for your file -- if the icon says C++, then the extension is wrong. If you chose "New File" from inside Visual Studio, then you're probably sunk -- at best you might have a file like helloworld.c.cpp, which doesn't quite count.)

  8. #53
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Quote Originally Posted by tabstop View Post
    Visual Studio's compiler has a C compatibility switch you can flip, /Tc (somewhere I forget where). You should be getting that automatically if your file ends with .c instead of .cpp. (The easy way to check is to get into Windows and browse for your file -- if the icon says C++, then the extension is wrong. If you chose "New File" from inside Visual Studio, then you're probably sunk -- at best you might have a file like helloworld.c.cpp, which doesn't quite count.)
    I have no clue what you mean. I have no files to begin with. Second, I go to File-->New-->Project, enter a name such as C Programming.c and wipe out the default lines, and put the lines in that the book gives me. Would I be doing that right?

  9. #54
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Of course you have a file -- where do you think all that stuff that you type goes? It's probably hidden a bit, something like My Documents\Visual Studio\Projects\C Programming\this\that\theother\and\so\on. If you follow it all the way down, I wouldn't be surprised at all that you have "C Programming.c.cpp" as your filename.

    But no, if you choose File->New you won't get a C source file out of Visual Studio. If you're good with command line, you can rename the file, or do what I do when I have to compile a C file in Visual Studio which is roughly this:
    • Cry a little bit
    • Create a new file in notepad like "whatever.c" and put a few lines in it
    • Go to Visual Studio, and choose create empty project
    • Right click on the project name, choose add existing item
    • Find your whatever.c and select it

    I'm doing this from memory so the option names might be off a little bit.

  10. #55
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Quote Originally Posted by tabstop View Post
    Of course you have a file -- where do you think all that stuff that you type goes? It's probably hidden a bit, something like My Documents\Visual Studio\Projects\C Programming\this\that\theother\and\so\on. If you follow it all the way down, I wouldn't be surprised at all that you have "C Programming.c.cpp" as your filename.

    But no, if you choose File->New you won't get a C source file out of Visual Studio. If you're good with command line, you can rename the file, or do what I do when I have to compile a C file in Visual Studio which is roughly this:
    • Cry a little bit
    • Create a new file in notepad like "whatever.c" and put a few lines in it
    • Go to Visual Studio, and choose create empty project
    • Right click on the project name, choose add existing item
    • Find your whatever.c and select it

    I'm doing this from memory so the option names might be off a little bit.

    Too many files in there to see which are mine and which are the ones that came with it. I just scanned through the directories.

    Would it be the same thing if I put the lines in notepad the same as I am doing it now?

  11. #56
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Would C The Complete Reference would be a good book for someone that never programmed before?

  12. #57
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can write your source in notepad, yes, or any editor (emacs, vim, notepad++, or etc.).

    If you want to get retro, you can then take that file, go to your start menu and choose "Visual Studio <year> Command Prompt" (it's in your visual studio folder thing), navigate to where you saved your file, and type "cl filename.c" and hey presto.

  13. #58
    Registered User
    Join Date
    Apr 2006
    Posts
    61
    Quote Originally Posted by tabstop View Post
    You can write your source in notepad, yes, or any editor (emacs, vim, notepad++, or etc.).

    If you want to get retro, you can then take that file, go to your start menu and choose "Visual Studio <year> Command Prompt" (it's in your visual studio folder thing), navigate to where you saved your file, and type "cl filename.c" and hey presto.

    tabstop,

    Would The Complete Reference of C be a good book for total beginners? I hope the answer is yes.

    To be honest, I honestly stopped reading The C Programming Language. My last part was about Fahrenheit and Celisus. I said I gave up with that book and I meant it.

  14. #59
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I assume you're talking about Schildt's book. I don't own it, haven't read the whole thing, just standing in the bookstore. I can't recommend it.

    There's a whole thread about good books stickied at the top of the forum.

  15. #60
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,169
    Quote Originally Posted by tabstop View Post
    2. As for main vs. int main, K&R get a pass, since they wrote the language and they didn't require int main. Now since you are using a C++ compiler (for whatever reason only you know) you're getting in trouble, since C++ closed down that loophole and require int main. If you were compiling a .c file, using C settings you'd get a warning about it but not an error.
    But the thing is that if you write good, conforming code, it will work just as well under C++ as C. I you don't need to work for embedded systems & all that (just learning still), then you can avoid all the loopholes of C by compiling it as C++.
    For example, it disallowed the use of implicit main in the book. If you'd written code with a C compiler instead, it would compile, but you would be told by the members of this board to correct it.
    And VC++ does not warn about implicit main from what I can remember.

    Quote Originally Posted by tabstop View Post
    You can write your source in notepad, yes, or any editor (emacs, vim, notepad++, or etc.).
    Just a note, though. Don't use notepad.
    Yes, you can use any editor, but I would still recommend Visual Studio. It's a good IDE.

    If you want to get retro, you can then take that file, go to your start menu and choose "Visual Studio <year> Command Prompt" (it's in your visual studio folder thing), navigate to where you saved your file, and type "cl filename.c" and hey presto.
    I don't know if you can trust that. VC++'s compiler is known not to be too friendly on the command line. Better throroughly study the documentation first.

    So I'll continue to recommend that you compile under the IDE.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 4 of 6 FirstFirst 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem about making setup project
    By sgh in forum Windows Programming
    Replies: 0
    Last Post: 04-30-2008, 03:09 AM
  2. Add a VS 2K8 express template for .c
    By vtechv in forum C Programming
    Replies: 2
    Last Post: 02-11-2008, 02:13 AM
  3. How to add a file to a project in bloodshed.
    By Smeep in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 09:29 PM
  4. Project details: Dedicated
    By Stack Overflow in forum Projects and Job Recruitment
    Replies: 9
    Last Post: 02-22-2005, 02:10 PM
  5. Can somebody test this code please
    By andy bee in forum C Programming
    Replies: 6
    Last Post: 10-09-2001, 03:08 PM

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