Maspital
Maspital

Reputation: 26

Running C Program in Cygwin doesn't generate any outcome

While writing a simple C Program i encountered the problem that "printf" doesn't generate any outcome. Code:

#include<stdio.h>
int main()
{
printf("Hello World\n");
}

Cygwin log after compiling and running:

MMGV@Philipp /cygdrive/c/users/MMGV/Desktop/Programme
$ gcc test.c -o test.exe

MMGV@Philipp /cygdrive/c/users/MMGV/Desktop/Programme
$ test.exe

MMGV@Philipp /cygdrive/c/users/MMGV/Desktop/Programme
$

No error message, simply nothing. Opening the generated .exe in the Windows GUI does not work either. Thanks for any help!

Upvotes: 1

Views: 1400

Answers (3)

SHRIKANT PATIL
SHRIKANT PATIL

Reputation: 1

This worked!

#include <stdio.h>
#include <stdlib.h>

int main(void){
  printf("Hello World.\n");
  return EXIT_SUCCESS;
}

cmd:

HP@LAPTOP-VUS0RJO0 /cygdrive/c/cygwin64/home/shri
$ gcc -o first first.c

HP@LAPTOP-VUS0RJO0 /cygdrive/c/cygwin64/home/shri
$ ./first.exe
Hello World.

HP@LAPTOP-VUS0RJO0 /cygdrive/c/cygwin64/home/shri
$

Upvotes: 0

user58697
user58697

Reputation: 7923

You are not running your program. Cygwin shell by default doesn't have current directory in the path. test.exe is resolved to a standard Unix-like utility (try which test). You need to specify current directory explicity:

$./test.exe 

Upvotes: 2

Weather Vane
Weather Vane

Reputation: 34583

Change your program to

#include<stdio.h>
int main()
{
    printf("Hello World\n");           // add newline
    getchar();                         // wait for an input (newline)
}

Because in Windows, the console window probably closes before you have a chance to see it.

Upvotes: 2

Related Questions