Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Learngin C

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
ricanlinux
Posts: 63
Joined: 2007-05-02 00:02

Learngin C

#1 Post by ricanlinux »

Hey I am new to C and I am using an online tutorial just to play around and see how i do. well i wrote a little program like the tutorial said but it is not doing what it is suppose to. here is the out put:
rican-linux@debian:~/programs$ cat hello.c
#include < stdio.h>

void main()
{
printf("\nHello World\n");
}
rican-linux@debian:~/programs$ gcc hello.c
hello.c:1:20: error: stdio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
hello.c:4: warning: return type of ‘main’ is not ‘int’

any ideas?

User avatar
sinical
Posts: 1012
Joined: 2007-03-25 11:52

#2 Post by sinical »

Typos are the enemy

Code: Select all

#include < stdio.h> 
should be

Code: Select all

#include <stdio.h>
also make sure you have libc6-dev installed - recompile and see what else pops up
Every cloud has a silver lining, except for the mushroom shaped ones, which have a lining of Strontium 90.
---------------------------------------------
umop apisdn

ricanlinux
Posts: 63
Joined: 2007-05-02 00:02

#3 Post by ricanlinux »

i do have libc6-dev and i did that changbe and this is the out put:
rican-linux@debian:~/programs$ gcc -o hello hello.c
hello.c: In function ‘main’:
hello.c:4: warning: return type of ‘main’ is not ‘int’

User avatar
chealer
Posts: 680
Joined: 2005-09-24 16:11
Location: Kebekia, Kanada
Has thanked: 2 times
Contact:

#4 Post by chealer »

ricanlinux wrote:rican-linux@debian:~/programs$ gcc -o hello hello.c
hello.c: In function ‘main’:
hello.c:4: warning: return type of ‘main’ is not ‘int’
That's normal, since your main is returning void rather than int.

saline
Posts: 2
Joined: 2006-11-29 19:56

#5 Post by saline »

to get rid of that, declare main as:

int main()

typically you will see:

int main(int argc, char *argv[])

or similar.

ricanlinux
Posts: 63
Joined: 2007-05-02 00:02

#6 Post by ricanlinux »

I did it and it worked!

ricanlinux
Posts: 63
Joined: 2007-05-02 00:02

#7 Post by ricanlinux »

here is another issue i am throwing out there! i am using a text to learn C and it gave an example i tried to compile here is the example:

include <stdio.h>

/*
* Tell the compiler that we intend
* to use a function called show_message.
* It has no arguments and returns no value
* This is the "declaration".
*
*/

void show_message(void);
/*
* Another function, but this includes the body of
* the function. This is a "definition".
*/
main(){
int count;

count = 0;
while(count < 10){
show_message();
count = count + 1;
}

exit(0);
}

/*
* The body of the simple function.
* This is now a "definition".
*/
void show_message(void){
printf("hello\n");
}

and here is the output:
rican-linux@debian:~/programs$ gcc -o ex1-1 ex1-1.c
ex1-1.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
ex1-1.c: In function ‘main’:
ex1-1.c:25: warning: incompatible implicit declaration of built-in function ‘exit’
ex1-1.c: At top level:
ex1-1.c:32: warning: conflicting types for ‘show_message’
ex1-1.c:21: warning: previous implicit declaration of ‘show_message’ was here
ex1-1.c: In function ‘show_message’:
ex1-1.c:33: warning: incompatible implicit declaration of built-in function ‘printf’

any thoughts?

User avatar
sinical
Posts: 1012
Joined: 2007-03-25 11:52

#8 Post by sinical »

you are missing a '#' in front of hte include

like i said before.. typos are the enemy
Every cloud has a silver lining, except for the mushroom shaped ones, which have a lining of Strontium 90.
---------------------------------------------
umop apisdn

Post Reply