Displays the error given in the header. I found the code, rewrote it myself, but it still gives an error.

And I also understood correctly what the window should show where to enter my character?

#include <stdio.h> main (); { char ch; ch = getchar(); putchar(ch); } 
  • one
    I wonder how it came to linking ... Didn’t there have been error: expected identifier or '(' before '{' token - Sergey
  • It was in the online compiler, and did not understand, unfortunately, what is the essence of the error - Elvis
  • I did not understand the essence of the error - I am afraid that no one will understand this. If you remove the semicolon and copy it with the usual gcc , then everything is going fine and the program works. Is it necessary to use Sublim? - Sergey
  • I would like to use only it: ( - Elvis
  • @Elvis, put all the libraries and packages needed to build. It is likely that the linker simply does not know what to do next with the object manager, since the build infrastructure is not worthwhile or the packages are crookedly installed. And yes, error messages are nowhere to be seen. Give the entire text of the output. - 0andriy

4 answers 4

Remove semicolon after

 int main(); 

!!!

    First, you need to remove the semicolon after main() , and secondly, in an amicable way, ch should be of type int (although in this case it is not fundamental).

    You can do it without it :)

     int main() { putchar(getchar()); } 
    • semicolon removed for a long time, but, unfortunately, the same mistake - Elvis
    • ideone.com/IF7Exx Something's not on your local system ... - Harry
    • what can be done? - Elvis
    • Well, you know, remotely you don’t understand what is going on there ... :( - Harry

    Your cool program should look like this.

     #include <stdio.h> int main( void ) { int ch; ch = getchar(); putchar( ch ); } 

    Or

     #include <stdio.h> int main( void ) { int ch; ch = getchar(); if ( ch != EOF ) putchar( ch ); } 

    Keep in mind that in order to wait for the output of the program, you must press the Enter key after the entered character.

    • Unfortunately, all the same error - Elvis
    • @Elvis And what does the full text of the error message look like? And which compiler do you use? - Vlad from Moscow
    • As a beginner, I was advised to use the compiler in the sub-license, but the error itself "C collect2.exe: error: ld returned 1 exit status [Finished in 0.1s]" - Elvis

    No karma to comment, so I will answer.

    collect2.exe: error: ld returned 1 exit status does not indicate which error was, but indicates that there was an error before that. Therefore, in order to help something, we must know the real mistake. Dig in the logs or recent messages, looking for the error itself.