Thread: Code won't compile! O.o

  1. #16
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Another suggestion..

    you have around 150 lines of code there.. that is... well quzah summed it up..

    maybe you should try to build your program a little by little... get one *small* part working, then add somthing new. this way when you introduce a bug in the middle of writing it, you are not running all over the place trying to figure out what the problem is. you can narrow it down to what you changed last and what it affected..

    get the point..

    and of course pay attention to all the previous posts..

  2. #17
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    I've fixed all but 1 error in my code which the compiler comes up with:
    error C2664: 'fopen' : cannot convert parameter 1 from 'char' to 'const char *'
    It says this error for line 2 and 3 of the snippet below:
    Code:
    char line[8];
    ifp=fopen(inputFileName, "r");
    ofp=fopen(outputFileName, "w");
    /* Calculate each line until end of file */
    while(fgets(line, 8, ifp) != NULL) {
    	sscanf (line, "%c", &inputRoman);
    	/* Call calculation procedure */
    	romanToArabic();
    	/* Print result into output text file */
    	fprintf(ofp, "The Arabic numeral for %c is %i", inputRoman, outputArabic);
    }
    fclose(ofp);
    fclose(ifp);
    Outside of void main() is:
    Code:
    FILE *ifp, *ofp;
    char inputFileName, outputFileName, inputRoman;
    int outputArabic;
    Last edited by Coldcore; 01-06-2006 at 01:05 PM.

  3. #18
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    Quote Originally Posted by xhi
    Another suggestion..

    you have around 150 lines of code there.. that is... well quzah summed it up..

    maybe you should try to build your program a little by little... get one *small* part working, then add somthing new. this way when you introduce a bug in the middle of writing it, you are not running all over the place trying to figure out what the problem is. you can narrow it down to what you changed last and what it affected..

    get the point..

    and of course pay attention to all the previous posts..
    mate i know my code is crap but cant expect me to write this in the best way possible straight away. ive only ever done little programs to do small calculations before, this is the biggest program ive done and its nothin compared to what you guys can do i know. also, of that 150 lines of code is 40 lines of commenting. so 110 :P

  4. #19
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Quote Originally Posted by Coldcore
    mate i know my code is crap but cant expect me to write this in the best way possible straight away. ive only ever done little programs to do small calculations before, this is the biggest program ive done and its nothin compared to what you guys can do i know. also, of that 150 lines of code is 40 lines of commenting. so 110 :P
    i am in no position to call other people code crap.. i can barely remember what i learned yesterday to apply it to what i learn today.. so i am merely trying to suggest what i do to help myself.. compile often and fix little bits as i go..

    as for the current problem..

    i would think that it is with these lines ..

    char inputFileName, outputFileName, inputRoman;
    ifp=fopen(inputFileName, "r");
    ofp=fopen(outputFileName, "w");

    fopen is looking for a string (const char*).. and you are giving it a char
    try to do somthing like this..

    fopen("infilename", "r")

    or

    char filename[] = "inFileName";
    fopen(filename, "r");

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You should also check to make sure the files were opened, especially the one opened in read mode.

    And another thing:
    Code:
    output = output + "M";
    I assume this is trying to add "M" on to the end of the string output. Use strcat() for string concatenation.

    And re-read Quzah's post again.
    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. #21
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    There's an old saying that goes "No pain, no gain."

    So many times I see folks in here posting messages like:

    "Please look over my code. I'm not asking you to code my project, but I need to know why it doesn't work."

    Your compiler -- if properly set up -- will tell you what's wrong with your program. The reason you're not understanding what it is telling you is because you haven't learned to translate all of those error messages into words that YOU understand. Your compiler tends to assume that you ARE an experienced C programmer. (Wouldn't it be great, though, if a compiler had a --newb switch, to put those error messages in newb-speak!)

    The first time you pick over each and every compiler message, and figure out what it is telling you, it's a painful and time consuming process. But believe me, doing that will make you a better programmer.

    Most folks who are taking a C course in college or in high school are just concerned with getting the program to run, so that they can turn it in and get the grade. But it is my opinion that the learning REALLY comes when you're picking your way through all the errors that your first effort turns up. That PAIN is where you find your GAIN.

    If you run into a compiler message you don't understand, copy and paste it into the search box on Google. That one little act can save you hours of scratching your head. Yes, sometimes you have to sift through the chaff on Google before you find the wheat, but it IS helpful.

    Do that for a while, and you start to get a feel for what will and won't work.

    Now, all of that doesn't even begin to cover the process of debugging once you've gotten it to compile. But that's another topic for another day.

    Don't hesitate to ask for help on the forums for something you don't understand, but also, don't shy away from picking apart those error messages.

    Just my 2 cents worth......

  7. #22
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    xhi,

    fopen("infilename", "r")

    would having the variable "infilename" in quotes like this make it think thats the actual filename? the error dissapears using the quotes tho. the user inputs the text file name into the variable "inputFileName" and that is currently set to a char.. so is this why it needs to be in quotes to work? maybe it should be a float? ill read up on this later.

    fgw_three,
    thanks man.

    I did this earlier actually, went through each error message on google and managed to fix all apart from an error I get which doesnt specify a line number because its a general error. I tried to look up the definition of this error but its too general so I really dont know what is wrong.
    test.obj : error LNK2005: _main already defined in miniproject.obj
    Debug/miniproject.exe : fatal error LNK1169: one or more multiply defined symbols found
    im sorry for being another noob asking that same old senario, i guess i was just trying to find the easy way out. but thanks to you guys im not finding that route, which i am thankful for because ive actually learnt a little going through these errors. and its a greater satisfaction when you fix them.

    but this one i really am stuck on. ill carry on with trying to get it to work later today, and hopefully ill figure it out.

    thanks again.

  8. #23
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    >> would having the variable "infilename" in quotes like this make it think thats the actual filename?

    thats what i was getting at.. just as an example of what could be done.. if you did it this way infilename is what the file would be named just as if you did this..

    fopen("somefile.txt", "r");

    the file would be somefile.txt ..

  9. #24
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I tried to look up the definition of this error but its too general so I really dont know what is wrong.
    You have more than one main() function, get rid of all but one.

  10. #25
    Registered User
    Join Date
    Jan 2006
    Posts
    10
    ahh it was because i had another source file with main() in it, so i deleted that and now it compiles. now for the debugging

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code won't compile
    By monkles in forum C Programming
    Replies: 3
    Last Post: 05-28-2009, 01:45 PM
  2. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 09:36 AM
  3. This code won't compile in Red Hat Linux 9
    By array in forum Linux Programming
    Replies: 7
    Last Post: 04-27-2004, 06:30 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM