Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

miguel747

macrumors newbie
Original poster
Sep 25, 2011
6
0
Terminal bugged

After installing the Lion OS (it hasnt happened with SL) I observe that the Terminal when I execute a program in C and it out all desconfigured. I will be more clear: make the code in C (via Xcode 3.xx) when I type the command in terminal software gcc -Wall -lm teste.c -o teste the output for example the printf("Eu\n"); just out exactly the same: Eu\n and not simply "Ee" and a line in blank indiceted by \n.

Could Someone help me this question?

Follow the screen in my terminal background:

http://img855.imageshack.us/img855/6017/capturadetela20110924s0.png
 
Last edited:
Well, it works here why the -lm flags? Try this:

Code:
clang teste.c

-bash: clang: command not found


i use the default output "gcc -Wall -lm -o" is to math.h library but it can be disregards on this code.
 
-bash: clang: command not found


i use the default output "gcc -Wall -lm -o" is to math.h library but it can be disregards on this code.

What version of OS X are you using? You might not have clang and llvm if it's not recent. When I compile it with clang, I get this output (just a snippet).

******************************************************************
Aeroporto Internacional do Paraiso
******************************************************************
Hora Atual: 15:58:02
NVoos: 62
NApro: 21
Ndec: 41

Pista1:

Voo: AZ1009 [a(00)] Horario: - 15:58
Voo: LN7002 [a(01)] Horario: - 16:06
Voo: JJ4403 [a(10)] Horario: - 16:10
Voo: TG1505 [a(07)] Horario: - 16:14
Voo: AL0012 [a(10)] Horario: - 16:18
Voo: GL7603 [a(12)] Horario: - 16:22
Voo: VG3002 [a(01)] Horario: - 16:26
Voo: AZ1010 [a(10)] Horario: - 16:30
Voo: TT1010 [a(02)] Horario: - 16:34
Voo: TG1501 [a(10)] Horario: - 16:38
Voo: JJ4404 [a(05)] Horario: - 16:42

Pista2:

Voo: JJ4401 [a(01)] Horario: - 16:02
Voo: VG3003 [a(09)] Horario: - 16:06

math.h is part of the standard library: gcc -Wall progname.c should work. Anyway that's not it, I have tried what you did with gcc and it works as expected. I don't know, are you using rich text or something like that? Just a guess.
 
What version of OS X are you using? You might not have clang and llvm if it's not recent. When I compile it with clang, I get this output (just a snippet).


math.h is part of the standard library: gcc -Wall progname.c should work. Anyway that's not it, I have tried what you did with gcc and it works as expected. I don't know, are you using rich text or something like that? Just a guess.

I use Lion OS version 10.7.1. When i used the snow leopard the situation never happened.

"clang and llvm" how is it works? or install?

dont work. :(
 
I use Lion OS version 10.7.1. When i used the snow leopard the situation never happened.

"clang and llvm" how is it works? or install?

dont work. :(

clang/llvm should be pre-installed with the developer tools as far as I know. But I'm still running Snow Leopard here. But don't worry about it, it's not related to your problem.

Anyway are the text ascii? Seems odd that the new line characters are ignored.
 
I use Lion OS version 10.7.1. When i used the snow leopard the situation never happened.

"clang and llvm" how is it works? or install?

dont work. :(

I dont know what I do but works right now! :D

see it:

Thanks for help me!

I created the simple file text and change the extension .rtf to .c and open with xcode and paste the code and compile just the command -Wall programfile.c -o programfile and it works.
 

Attachments

  • Captura de Tela 2011-09-25 às 16.30.20.png
    Captura de Tela 2011-09-25 às 16.30.20.png
    102.2 KB · Views: 100
I created the simple file text and change the extension .rtf to .c and open with xcode and paste the code and compile just the command -Wall programfile.c -o programfile and it works.

If I understand what you did, then changing the extension from .rtf to .c is probably the cause of the problem.

Text in .rtf files is not stored as plain text. Backslashes have a special meaning. To let you type in backslashes, each literal backslash is actually stored in the RTF file as two backslashes.

I started with this fragment of C source:
Code:
printf("******************************************************************\n");
printf("               Aeroporto Internacional do Paraiso                 \n");
printf("******************************************************************\n");
The code is directly from the original uploaded source.

I made a new file in TextEdit and pasted that C code into it. I then saved it as .RTF.

Next, I changed the extension from .RTF to .C and opened it in Xcode. It looks like this:
Code:
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww13300\viewh9000\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0     
printf("******************************************************************[COLOR="Red"]\\n[/COLOR]");\
printf("               Aeroporto Internacional do Paraiso                 [COLOR="red"]\\n[/COLOR]");\
printf("******************************************************************[COLOR="red"]\\n[/COLOR]");\
}
I've hilited the double-backslashes in red.

Now, if you copy just the lines of printf's, and paste them into another file in Xcode, it will compile. This isn't a surprise; the code is legal C. However, the double-backslashes will be treated as literal backslashes by the C compiler. That's how C works. Look in any C reference book about how backslash is used in C strings and characters.

So if the double-backslash code is compiled, it will produce exactly the output appearing in the OP's first screenshot.


One way to avoid this problem is to never change .RTF extensions to .C. There's no reason to do this when simple strategies can safely avoid problems.

One simple approach is to open the .RTF file in Xcode, then copy and paste the lines of code into a .C file. Xcode is able to open RTF files, and copy text out of them. The copied text is the original text, without double backslashes.

Or open the .RTF in TextEdit and "Save as..." a plain text file. Then open the plain text file in Xcode and copy/paste into a .C file.

The simplest solution of all is to never edit code in TextEdit, and certainly never saved as RTF. Just use Xcode's editor for all editing of source files.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.