Thread: Illegal Characters error

  1. #1
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14

    Illegal Characters error

    Hi I am new here.

    I am also a beginner in C programming.
    I made a program that gets 10 values and then get its maximum, minimum or average.
    I have 6 files made.
    The project file, max.c, min.c, ave.c, numseq.h and numseq.c as the main file.

    Here is the code I have for numseq.c:

    Code:
    #include "NUMSEQ.H"
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    
    main()
    {
        float num [10], result;
        int choice, i;
        clrscr();
        printf("Input 10 numbers: \n");
        for(i=0;i<10;i++)
            scanf("%f", &num[i]);
        
        
        printf("MENU \n");
        printf("1. Find MAX \n");
        printf("2. Find MIN \n");
        printf("3. Find AVE \n");
        printf("4. Exit.");
        scanf("%d", &choice);
    
    
            switch(choice)
            {
                case 1:
                    result = float max(num[10]);
                    printf("\nThe maximum number is: %f", result);
                    break;
            
                case 2:
                    result = float min(num[10]);
                    printf("\nThe minimum number is: %f", result);
                    break;
            
                case 3:
                    result = float ave(num[10]);
                    printf("\nThe average is: %f", result);
                    break;
            
                case 4:
                    exit();
                    break; 
                
                default:
                    printf("Invalid input!!");
                    break;
            }
    }
    ERROR:

    Error C:\TC\NUMSEQ\NUMSEQ.C 24: Illegal character ' ' (0x03) in function main
    Error C:\TC\NUMSEQ\NUMSEQ.C 24: Illegal character ' ' (0x03) in function main
    Error C:\TC\NUMSEQ\NUMSEQ.C 24: Illegal character ' ' (0x03) in function main
    Error C:\TC\NUMSEQ\NUMSEQ.C 24: Illegal character ' ' (0x03) in function main
    ....



    I have set the folders and directories correctly but I still don't get it why I get these type of errors.


    Thanks for your help

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It means the program you are using to edit the source file is inserting characters that are not recognised by a C compiler as valid source code. Preventing that will depend on the specifics of your text editor, development environment, or whatever software you are using to edit your source code. You need to read the documentation for the tools you are using.

    At a guess, since a character with value 0x03 corresponds to the CTRL-C keystrokes (CTRL key and C key held down at the same time) you are trying to use CTRL-C to abort your editor, and it is inserting CTRL-C (ASCII code 3) characters into your source file. You therefore need to read the documentation to find out how to properly terminate the editor program.

    Note: there are other problems in your code, but you haven't asked about them.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14
    Thank you grumpy.
    The error is gone. Except that I'm still having 2 other errors.
    Expression syntax in function main.

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Grumpy is right.

    But the characters are more likely the unicode characters 0x030F and 0x030B that look pretty much like the ANSI " character but are actually a different character entirely. If you copy/pasted code from Word or the web or somewhere else these can sneak in. Check that all your " characters on line 24 are indeed the " character and not something that just looks like it.

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by moondrums View Post
    Thank you grumpy.
    The error is gone. Except that I'm still having 2 other errors.
    Expression syntax in function main.
    Code:
    result = float max(num[10]);
    What you you expect the lines similar to this to do (These are your syntax errors as you probably know)? More specifically, what do you want that float keyword to do?

  6. #6
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14
    Quote Originally Posted by Hodor View Post
    Code:
    result = float max(num[10]);
    What you you expect the lines similar to this to do (These are your syntax errors as you probably know)? More specifically, what do you want that float keyword to do?
    function float max() returns a value of a maximum number.
    I wanted the result to get what that value is.
    How do I do it right?

    Thanks

  7. #7
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    The type a function returns is only specified in it's declaration or prototype. Assuming that the function max() is implemented somewhere, you simply want:

    Code:
    result = max(num[10]);

  8. #8
    Registered User
    Join Date
    Dec 2013
    Location
    Cebu City, Philippines
    Posts
    14

    Talking

    Thanks.

    I have updated my codes
    The main c file:
    Code:
    #include "NUMSEQ.H"
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    
    
    
    main()
    {
        float num[10], result;
        int choice, i;
        clrscr();
    
    
        printf("Input 10 numbers \n");
        for(i=0;i<10;i++)
            scanf("%f", &num[i]);
    
    
                printf("MENU \n");
                printf("[1]Find Max \n");
                printf("[2]Find Min\n");
                scanf("%d", &choice);
    
    
    
    
                switch(choice)
                {
                    case 1:
                        result = max(num[10]);
                        printf("%f", result);
                        break;
    
    
                    case 2:
                        result = min(num[10]);
                        printf("%f", result);
                        break;
    
    
                    default:
                        printf("Invalid input!");
                        break;
                }
    
    
                return 0;
    }
    the min.c file
    Code:
    #include "NUMSEQ.H"
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    
    
    
    float min(float a[10])
    {
        int i;
        float mini = a[0];
        for(i=0;i<10;i++)
        {
            if(a[i]<mini)
                mini = a[i];
        }
        return(mini);
    }

    the max.c file
    Code:
    #include "NUMSEQ.H"
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    
    float max(float a[10])
    {
        int i;
        float maxi=-32000;
        for(i=0;i<10;i++)
        {
            if(a[i]>maxi)
            
                maxi=a[i];
        
        }
        return(maxi);
    }

    Run the program and now it's giving me 2 errors that says:
    Incompatible type conversion in function main()

    it's pointing to result = max(num[10]); and result = min(num[10]);

    Sorry for all these questions.
    This might sound stupid to you guys, but I still hope you can help me.

    Thank you!
    Last edited by moondrums; 12-09-2013 at 07:49 AM.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The max and min functions take an array as input. num[10] is not an array; it is a (non-existent) member of the array. The array itself is "num".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Illegal characters
    By Therry in forum C++ Programming
    Replies: 7
    Last Post: 04-19-2012, 09:05 AM
  2. Detecting illegal characters
    By paul_harris77 in forum C Programming
    Replies: 14
    Last Post: 02-28-2009, 02:58 PM
  3. Using illegal characters
    By Rommeo in forum C++ Programming
    Replies: 6
    Last Post: 07-28-2007, 02:15 AM
  4. Illegal use of IOS error
    By Xanth in forum C++ Programming
    Replies: 7
    Last Post: 02-26-2005, 02:26 PM
  5. Illegal Characters
    By Echidna in forum Windows Programming
    Replies: 3
    Last Post: 12-08-2002, 04:56 AM

Tags for this Thread