0

enter image description hereHere is my code

#include <stdio.h>
int main()
{
    int a;
    int b = 9;
    printf("input a integer: ");
    scanf("%d",&a);
    printf("%d + %d = %d\n",a,b,a+b);
    return(0);
}

Build message:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
ld.exe||cannot open output file G:\document\C++ and C\Add and Input.exe Permission denied|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I think my code is right. But I can't get it right to run smoothly.

kile
  • 141
  • 1
  • 7
  • 2
    Because your project/IDE is badly configured: no compiler. – kebs Dec 24 '19 at 15:23
  • Your code looks right (apart from treating `return` as a function) so the reason is in the parts that you don't show here. Guessing from the error, you haven't created an actual project that could be compiled. – Ulrich Eckhardt Dec 24 '19 at 15:24
  • @UlrichEckhardt: `return(0)` is valid in C. – machine_1 Dec 24 '19 at 15:26
  • In codeblocks, you must first create a project, then select that project in the tree on the left, then you can make a new file, select "console application", follow the menus, select "C" and the name of the program, you will then see it appear with a "hello world" template code, replace it with your current code, then run it – Benoit F Dec 24 '19 at 15:26
  • The brackets are superfluous, @machine_1, which is what I'm taking offence at. Of course, that doesn't make the code invalid in any way but it's a bad habit IMHO. – Ulrich Eckhardt Dec 24 '19 at 15:28
  • @UlrichEckhardt: For the record, those are "_parenthesis_" – machine_1 Dec 24 '19 at 15:31
  • `ld.exe||cannot open output file G:\document\C++ and C\Add and Input.exe Permission denied|` Your program did compile, but you set up your IDE to write the compiled program to a bad location. – zwol Dec 24 '19 at 15:49
  • There _is_ a problem with your code, but it's not a problem that makes it fail to compile. [`scanf` should not be used to read input interactively](https://stackoverflow.com/questions/58403537/what-can-i-use-for-input-conversion-instead-of-scanf). (I would go farther and say that none of the `scanf` functions should ever be used at all.) – zwol Dec 24 '19 at 15:52
  • @zwol There are so many alternatives. what do you recommend for replacing ```scanf```? – kile Dec 25 '19 at 01:27
  • Don't use `+` in a directory name in Microsoft OS – M.M Dec 25 '19 at 02:08
  • @M.M, You mean this G:\document\C ```++``` and C\Add? – kile Dec 25 '19 at 02:13
  • If you can create it in Explorer, it is probably a valid path, @M.M. At least that's what I would assume. It may well be that some programs are buggy, like that they can't handle paths with spaces. I'm very confident the OS is capable of handling valid paths, speaking from XP being the last version I used. – Ulrich Eckhardt Dec 27 '19 at 10:00
  • @UlrichEckhardt can all 3rd party tools handle it though? – M.M Dec 27 '19 at 10:42
  • I meant exactly that, @M.M: "It may well be that some programs are buggy" BTW: That also implies that if a change to the directory name causes the thing to suddenly compile without problems, then it's a bug in one of the used programs and deserves a bug ticket. – Ulrich Eckhardt Dec 27 '19 at 11:05
  • @kile The discussion I linked to gives several good suggestions for avoiding `scanf`. – zwol Dec 27 '19 at 19:16

1 Answers1

1

Follow these steps to configure your project with CodeBlocks (in my case the project name is "containers").

1 - right click on your project icon :

enter image description here

2 - select "build options for debug or/and release:"

enter image description here

3- select "compiler settings" and then check the box corresponding to your option :

enter image description here

Saif Faidi
  • 509
  • 4
  • 15
  • I can't find there is a project. It's just a c file. I write this with "Ctrl-Shift-New". Anyway, thank you for your answer. – kile Dec 25 '19 at 01:47