0

I am just getting introduced to string in C, and my teacher uses CodeBlocks on windows and I'm using Xcode. He introduced me to this:

#include <stdio.h>
#include <string.h>
int main()
{
    char name[15];
    printf("Enter your name ");
    scanf("%[^\n]s\n",&name);
    printf("Welcome, %s !",name);
    size_t a=strlen(name);
    printf("Your name is %zu\n",a);
    strupr(name);
    printf("\n")
}

But when I do this same program in Xcode, strupr(name); doesn't work and shows the error:

Implicit declaration of function 'strupr' is invalid in C99.

So I came back to SO to look for possible solutions. There was one where it said to go to language dialect and change it to C11. I did it, but it still would not execute, showing the same error message. Do I need to do something else to make it run?

Thanks

  • 1
    Did you *teacher* really give you that code? With the `gets` function, that is so [dangerous](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used) it has even been removed from the C language?' – Some programmer dude Mar 30 '22 at 14:59
  • And the error message you get mentions `strupr` which isn't a standard function, and isn't even used in the code you show. So the code you show isn't the code you build. Please take some time to read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And show us a proper [mre]. – Some programmer dude Mar 30 '22 at 15:00
  • @Someprogrammerdude yeah, he did. But Xcode showed a message saying it was dangerous so I searched it on my own. I'll bring this issue to him tomorrow – Glowing_glasses Mar 30 '22 at 15:01
  • @Someprogrammerdude Sorry, I didn't realize I had copied another code. I'll try to review my questions better from now. – Glowing_glasses Mar 30 '22 at 15:08
  • No problem! Anytway, tjhe problem is that there's no standard `strupr` function, so it's not declared anywhere. Before the C99 standard, it was allowed to use function without declarations, but it's not anymore, which is what the compiler is telling you. – Some programmer dude Mar 30 '22 at 15:10
  • @Someprogrammerdude Ohh, so it's not because of C99 but because codeblocks ran on an older version?? – Glowing_glasses Mar 30 '22 at 15:13
  • More likely the teachers "standard" C library have the `strupr` function as an extension to the standard, which isn't portable. My guess is that the teacher is on a Windows system. It's rather simple to implement a `strupr` function, and there are also plenty of examples if you search around a little. :) – Some programmer dude Mar 30 '22 at 15:16
  • @Someprogrammerdude okay. I was thinking it was a problem in my computer. Thank you very much – Glowing_glasses Mar 30 '22 at 15:20
  • https://stackoverflow.com/q/26327812/1271826 – Rob Mar 30 '22 at 15:20
  • 1
    @Rob Much appreciated. Thank you for this.! :D – Glowing_glasses Mar 30 '22 at 15:30

0 Answers0