Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find the error in following code :- expected unqualified-id before try()

Tags:

c++

#include<stdio.h>
#include<string.h>
void try(char s[])
{
    if(strlen(s)>5)
    {
        puts("Error\n");
    }
}
int main()
{
    char string[10];
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",&string);
        try(string);
    }

    return 0;
}

Still can't find the error... try is a simple function and as always i am creating a func and calling it. compiler is giving error - (expected unqualified-id before 'try')

like image 788
Raman Singh Avatar asked Nov 02 '25 05:11

Raman Singh


1 Answers

I suspect you are trying to compile your code as C++ rather than C. In C++, try is a reserved word (it is used in exception handling).

$ gcc test.c
$ g++ test.c
test.c:3:6: error: expected unqualified-id before 'try'

You can use -x to set the language explicitly (with either gcc or g++):

$ gcc -x c test.c
$ gcc -x c++ test.c
test.c:3:6: error: expected unqualified-id before 'try'
like image 128
NPE Avatar answered Nov 03 '25 21:11

NPE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!