Thread: Can't get program to work

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    Angry Can't get program to work

    Ok, I've been working on that morse code program,and keep getting 2 errors.Any one has any ideas waht wrong.The hradder files work fine


    /*Program to convert morse code in to alphanumeric, and vice versa
    Autor:A Mac Hugh
    Start Date: 31-05-2002
    Version:1.0

    Errors:- line 26: parse error before [
    line30 :confused by earlier errors,bailing out*/

    void morse_code (); // Fuction pototype
    //void alpha(); // Fuctiuon pototype
    char sentance[10];

    #include <stdio.h>
    #include "ailin.h" // header files
    #include "morsecode.h"
    void main (){
    int a;
    int b ;

    printf(" Enter in your sentance(max 10 charcters)/n");

    scanf("%s",&sentance);

    printf(" To cover to Morse code press 1/n/n/tTo covet to Alphanumeric press 2");

    scanf("%d",&a);
    scanf("%d",&b);

    if(a = 1)
    sentance[] = alpha() ;// fuction alpha beging used

    else if(b = 2)
    sentance[] = morse_code () ; // fuction morse_code beging used
    }
    /*Converts to morse usiing fuctions from head file morsecode.h?*/

    void morse_code() {

    one ( sentance[]);
    two( sentance[]);
    three( sentance[]);
    four( sentance[]);
    five(sentance[]);
    six( sentance[]);
    seven( sentance[]);
    nine( sentance[]);
    ten( sentance[]);
    }

    }




  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Problem 1:

    void main (){

    Don't use 'void main'. It is wrong. Use 'int main' and at the end of the main funciton, use 'return 0;' or whatever return value you feel you need to use.

    Furthermore, you really should use:

    int main ( void )

    To show that you mean for main to not have any paramaters.



    Problem 2:


    int a;
    int b ;

    printf(" Enter in your sentance(max 10 charcters)/n");

    scanf("%s",&sentance);


    Where exactly is 'sentance' declared? I don't see it. Is it in a header file? If so, it really shouldn't be. You don't create variables in header files typically.

    If not, then that is a problem. You're trying to use a non-existing variable.



    Problem 3:


    printf(" To cover to Morse code press 1/n/n/tTo covet to Alphanumeric press 2");

    scanf("%d",&a);
    scanf("%d",&b);


    Why are you scanning two variables here? You should only need one.



    Problem 4:

    if(a = 1)

    Um. No. This will always evaluate as true. This is 'valid', if by valid code you mean it's legal in C, but it is not what you want it to be. You want:

    if( a == 1 )



    Problem 5:

    sentance[] = alpha() ;// fuction alpha beging used

    Here we have a new data type called miracle, because it'd be a miracle if you got this to compile.

    What exactly are you trying to do? Does 'alpha()' return a character pointer? If so, then 'sentance' is what exactly? A character array? Ok... so if that's the case, you can make this sort of assignment ONLY if you specify the index of the single character to modify, or, if you are using something like strncpy or something similar to overwrite it.

    This is horribly wrong. If 'sentance' were an array of characer pointers, then this could work, but again, you'd have to actually specify an array index to assign the return value to.



    Problem 6:

    else if(b = 2)

    The same problem as with problem 4.



    Problem 7:

    sentance[] = morse_code () ; // fuction morse_code beging used

    The same problem as problem 5.

    After this, main ends so you should include your return line here.



    Problem 8:
    void morse_code() {

    See problem 7? See the problem? 'morse_code' is expected to have a return value when you use it up there, but here you don't give it one. Now do you see the problem?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. threaded program doesn't work?
    By OcTO_VIII in forum Linux Programming
    Replies: 1
    Last Post: 12-11-2003, 12:37 PM
  4. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 11:05 AM
  5. how does this program work
    By ssjnamek in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2002, 01:48 PM