LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to save my code? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-save-my-code-813197/)

bobnos 06-09-2010 01:35 PM

How to save my code?
 
Hello and Good Evening to everyone!

Situation:

I've written the following code in Vim (trying to write in C)

PHP Code:

#include<stdio.h
/* To prwto mou programma */
int main (void)
{
printf("Hello, world!\n");

return 
0;


And that's were I got stacked :P

I don't know how to save my file (example: hello.c)

(that's a classic example as you know :P)

I just don't get it..

Any help?

Thank you in advance :)

P.S: Here is a screen shot of my situation..

Sreen shot

business_kid 06-09-2010 01:39 PM

Vim is crazy. Once you get there, type ESC : wq and then press return

the ':' puts it in command mode

Tinkster 06-09-2010 01:40 PM

Heh ... welcome to LQ!


You need to find a vi tutorial or cheat sheet ;}


Code:

<ESC>:wq
will save your file and quit vim


Cheers,
Tink

bobnos 06-09-2010 01:47 PM

Thanks!
 
Thank you both of you!

I finally got it :P

@Tinkster

Do you have any link to get a -really good- vim tutorial?

edit: I type the following command in terminal:

Code:

bobnos@ubuntu:~$ gcc hello.c -o hello.out
and I get this error:

Code:

hello.c:1:17: error: missing terminating > character
what is that and how can I fix it?

Thnx

Nylex 06-09-2010 02:12 PM

For your include directive, you need #include <stdio.h>. The ">" at the end is missing. Really, though, the error message should have been sufficient - it even tells you the line number where the problem is!

onebuck 06-09-2010 03:25 PM

Hi,

Welcome to LQ!

Learning vi - "cheat sheet" technique is a good tutorial that will show you how to use vi, a powerful visual editor.

:hattip:
The above link and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

grail 06-09-2010 07:03 PM

You will soon learn that vim also has a heap a ways of doing things, but I just thought I would add that the following are equivalent:

Code:

<ESC>:wq

<ESC>:x


shai333 06-10-2010 12:30 AM

In addition to everything that has been said,
you might wanna try using an easier tool, such as Geany.

bobnos 06-10-2010 02:54 AM

Thank you for your answers.

But I've still have a problem :p

I add > as someone told me before.

Then I wrote this code:

PHP Code:

gcc hello.-o hello.out 

hello.out created but..

When I open it, nothing happen. Does anyone know why? :S

grail 06-10-2010 03:00 AM

Quote:

When I open it, nothing happen. Does anyone know why?
Please explain what you mean by "open"?

You should be executing hello.out:
Code:

./hello.out

alan99 06-10-2010 04:08 AM

Quote:

Originally Posted by bobnos (Post 3998637)
Thank you for your answers.

But I've still have a problem :p

I add > as someone told me before.

Then I wrote this code:

PHP Code:

gcc hello.-o hello.out 

hello.out created but..

When I open it, nothing happen. Does anyone know why? :S

gcc will just compile it to object code. I think he forgot the next step. It must be linked. The linker will insert some 'headers' in the object file telling the operating system where to find the entry point for the code and any parameters it may be passing.

alan99 06-10-2010 04:13 AM

Most systems will probably be using ELF as the executable format. a.out may not work on his system.

timmeke 06-10-2010 04:54 AM

As for vi, typing
Code:

ZZ
will also save + quit, without the need for command mode.

sica07 06-10-2010 06:00 AM

For a good vi tutorial read A byte of Vim

Aquarius_Girl 06-10-2010 06:54 AM

Quote:

Originally Posted by bobnos (Post 3998637)
Thank you for your answers.

But I've still have a problem :p

I add > as someone told me before.

Then I wrote this code:

PHP Code:

gcc hello.-o hello.out 

hello.out created but..

When I open it, nothing happen. Does anyone know why? :S

See if the following thread helps you !
http://www.linuxquestions.org/linux/...grams_on_Linux


All times are GMT -5. The time now is 01:47 PM.