about GCC: how do I compile a 1.c file?

Booting, installing, newbie
Post Reply
Message
Author
Guest

about GCC: how do I compile a 1.c file?

#1 Post by Guest »

I created my file 1.c very simple like this :

Code: Select all

#include <stdio.h>

main()
{
	int i;
	int j;
	printf("Put a number");
	scanf("%d",&i);
	j = i*i;
	printf("The result is %d",j);
}

then I use : gcc 1.c -o test1
But when I run test1 , there's nothing
So I how can I compile .c file and run it?

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#2 Post by GuestToo »

it works for me ... do you have usr_devx.sfs installed?

# gcc 1.c -o test1
# ./test1
Put a number25
The result is 625#

(by the way, test1 is ok, but -o test may cause confusion ... there is already a system program called test)

Guest

#3 Post by Guest »

Thanks , I use rxvt and type ./test1 , it work . But why when I click on it , it don't work . And why it's ./test1 , it's not test1
:D

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#4 Post by GuestToo »

your program is a console (text mode) program

if you click on it, it runs, but you don't see anything, because you would have to run it in a terminal emulator (like rxvt), and clicking the program does not automatically run it in a terminal emulator

Linux usually sets up the PATH (in /etc/profile) to include various default directories, like /bin, /sbin, /usr/bin, etc etc etc ... it could include the current directory (.) in the PATH, but it does not ... this is supposed to be for security reasons ... Windows does include the current directory in the PATH

so if you want to run a program in the working directory, you have to specify the full PATH to the file ( ./ )

Post Reply