Author Topic: don't compile a small Cpp language with Code::Block  (Read 18956 times)

Offline iop184

  • Single posting newcomer
  • *
  • Posts: 4
don't compile a small Cpp language with Code::Block
« on: April 24, 2014, 04:02:02 pm »
I am a freshman about Code::Block. I can run the code by itself in the Code::Block, produce ''Hello  world!''.  However, don't run the small code, as follow:
Code
main()
{
    int i,j,k;
    printf("\n");
    for(i=1; i<5; i++)
        for(j=1; j<5; j++)¡¡
            for (k=1; k<5; k++)
            {
                if (i!=k&&i!=j&&j!=k)
                    printf("%d,%d,%d\n",i,j,k);
            }
}



The Block Log says that:
Code
mingw32-g++.exe   -c ji.cpp -o ji.o
ji.cpp:6:9: error: stray '\302' in program
         for(j=1; j<5; j++)隆隆
         ^
ji.cpp:6:9: error: stray '\241' in program
ji.cpp:6:9: error: stray '\302' in program
ji.cpp:6:9: error: stray '\241' in program
ji.cpp: In function 'int main()':
ji.cpp:4:16: error: 'printf' was not declared in this scope
     printf("\n");
                ^
Process terminated with status 1 (0 minute(s), 0 second(s))
5 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

-------------- Run: Debug in xz (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Users\Administrator\Desktop\xz\bin\Debug\xz.exe
Executing: "C:\CodeBlocks/cb_console_runner.exe" "C:\Users\Administrator\Desktop\xz\bin\Debug\xz.exe"  (in C:\Users\Administrator\Desktop\xz\.)
Process terminated with status -1073741510 (0 minute(s), 2 second(s))
 

-------------- Run: Debug in xz (compiler: GNU GCC Compiler)---------------

Checking for existence: C:\Users\Administrator\Desktop\xz\bin\Debug\xz.exe
Executing: "C:\CodeBlocks/cb_console_runner.exe" "C:\Users\Administrator\Desktop\xz\bin\Debug\xz.exe"  (in C:\Users\Administrator\Desktop\xz\.)
Process terminated with status -1073741510 (0 minute(s), 1 second(s))

 I have no idea about this! Could you tell me how can run the small code correctly? 

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: don't compile a small Cpp language with Code::Block
« Reply #1 on: April 24, 2014, 04:28:00 pm »
1) never send me a private message with the same question... Please post it in the forum...
2) you have still a mall encoding or you add some cryptic unicode characters to your file. as you can see in the build log, gcc finds some cryptic Japanese characters at the end of the for loop. You have to remove them...
2.1) to fix the encoding Edit->File Encoding-> ASCHII or UTF-8 . Now delete all malformed characters
3) You don't have included stdio (if you are compiling only c code,what you code is at the moment, please use the file extension .c not .cpp)

greetings

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: don't compile a small Cpp language with Code::Block
« Reply #2 on: April 24, 2014, 04:29:26 pm »
Quote
ji.cpp:4:16: error: 'printf' was not declared in this scope
     printf("\n");
You need to at least add some include headers. But I think this is a C language related question, you can asked such questions on C Board - Cprogramming .com.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline iop184

  • Single posting newcomer
  • *
  • Posts: 4
Re: don't compile a small Cpp language with Code::Block
« Reply #3 on: April 25, 2014, 08:44:33 am »
Hello, BlueHazzard and ollydbg! The bug is resolved by your suggestions. Thank you very much!