Home Forums C Programming Linker Errors, i do believe i need help

Viewing 5 reply threads
  • Author
    Posts
    • #2181
      AnnelieSchoenhe
      Participant

      Okay, I’m studying C in order to code homebrew for the PSP kernal 3.XX and higher. (No Kxploit). Thing is, i’m starting out creating regular computer programs first. But wait, the tutorial i’m using doesn’t explain errors. So here I am, staring at two linker errors regarding functions. I’ve seperated the functions from the main function so i can work on them seperately in differn’t source files. I’m a new person to this coding business, so if you need my code or such, i’ll gladly post up here. Its nothing no one can do. ^_^

    • #3524
      GWILouisaxwzkla
      Participant

      Would help to post your code and errors. Make sure that the file your including has the correct “include” syntax , like:



      #include "c:myfile.cpp"

      and make sure that your function prototypes and declarations match perfectly or the linker will not associate the two correctly….

    • #3525
      AnnelieSchoenhe
      Participant

      Before i start, i fortunetly was able to fix the Linker errors. I fear i may have more of them later, but when that time comes, i’ll fix them. Now i have new errors.

      //A basic two in one program used for studying functions and arithmatic.
      //Created by Deathscreton on 5:08 PM 3/20/09
      #include

      addition()
      { do
      {
      char counter,addy,back,exit,yes,no;
      int count;
      int a;
      int b;
      int sum;
      count=0;
      counter='d';
      addy='g';
      back='f';
      exit='k';
      yes='n';
      ++count;

      printf("Please enter the first number: n");
      scanf("%d",&a);
      printf("You've entered %d, is this correct? Y for yes, n for no.",a);
      scanf("%c %c",&yes, &no);
      if (yes=='y')
      {
      printf("Please enter the second number: n");
      scanf("%d",&b);
      printf("You've entered %d, is this correct? y for yes, n for no.",b);
      scanf("%c %c",&yes, &no);
      if (yes=='y')
      {
      sum=a+b;
      printf("The answer of the numbers entered is %d. Would you like to run this again?",sum);
      scanf("%c %c",&yes, &no);
      if (yes=='y')
      {
      addition();
      }
      else (no=='n');
      {
      main();}
      }
      else (no=='n');
      {
      addition();
      }
      }
      }while (count < 48793);

      }



      counting()
      {

      do
      {
      int count;
      char yes;
      char no;
      char exit;
      exit='e';
      count=-89898;
      yes='h';
      no='b';
      printf("Press 'x' to exit the counter, press any other key to start. n");
      scanf("%c",&exit);
      if (exit=='x')
      { break;}
      do
      {
      ++count;
      printf("The counter is now at %d n",count);
      }while (count < 898989);
      printf("The final count number is %d n",count);
      printf("Would you like to run the counter again? y for yes n for no.");
      scanf("%c %c",&yes,&no);
      if (yes=='y');
      {counting();}
      else (no=='n');
      {main();}
      }while (exit=='b');
      }
      }


      int main()
      {
      char start;
      char counter;
      char addy;
      char back;
      char exit;
      char yes;
      char no;
      int count;
      int a;
      int b;
      int sum;
      count=-897989;
      counter='d';
      addy='g';
      back='f';
      exit='k';
      yes='n';
      start='o';

      printf("Welcome to the Basic two in one program created by Deathscreton(a small time coder on his way to PSP homebrew.) n");
      printf("This Basic two-in-one program contains a primative addition calculator and a high sped up counter from the numeric number -897989 to +48793. n");
      printf("You will now be prompted to chose the Addition calculator, or the counter. n");
      printf("For the addition calculator, press a then enter. For the counter, press c then enter. To exit the program, press x then enter. n");
      scanf("%c %c",&addy,&counter,&exit);
      if (addy=='a')
      {addition();}
      else (counter=='c');
      {counting();}
      else (exit=='x')
      {break;}
      return 0;}

      Thats the code, now here are the current errors:


      In function ‘addition’:
      Line 49 :’count’ undeclared (first use in this function
      (Each undeclated identifier is reported only once
      for each function it appears in.)
      In function ‘counting’:
      Line 82: syntax error before “else”
      Line 84: ‘exit’ undeclared(first use in this function)
      At top level:
      Line 86: syntax error before ‘}’ token
      In function ‘main’:
      Line 119: syntax error before “else”


      Those are the errors. I don’t understand why the pop up. I fix one, and another two take that one’s place. What in the world is going on?

    • #3526
      JonathaThurston
      Participant

      When your using an if/else statement you can’t give a condition to the else instead you should use else if(condition).


      if(i != x){
      ...
      }
      else if(i == j){
      ...
      }
      else(){
      ...
      }

      Also your calling int count at the start of the function and again at the start of your do/while loop.

    • #3527
      AnnelieSchoenhe
      Participant

      Wait, so the first else after the initial if should be if followed by a else Which is the second else in the statement right?

      if(exit=3)
      {.....
      }

      //This is where i'm confused
      //This is where the else if should be first right? Then an else should be right after it?
      else if(exit==23){
      ...
      }
      else(exit==46){
      ...
      }

      And even after that, i still recive errors up the ass. I built this code form the floor. How did these codes slip past?

    • #3528
      JonathaThurston
      Participant

      Here read http://www.cprogramming.com/tutorial/c/lesson2.html for information on if/else statments, and your if should be

      if(exit == 3) not if(exit = 3e)

      as what you did assigns 3 to exit.

Viewing 5 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.