Resolved [Help] Terminal MACOSX output strange caracters

Discussion in 'Mac Programming' started by miguel747, Sep 25, 2011.

  1. miguel747, Sep 25, 2011
    Last edited: Sep 25, 2011

    miguel747 macrumors newbie

    Joined:
    Sep 25, 2011
    #1
    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
     
  2. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    We need to see your actual code.

    Post the source code of "teste.c".
     
  4. miguel747 thread starter macrumors newbie

    Joined:
    Sep 25, 2011
    #4
    it is http://pastebin.com/zY1XAUj2


    the event simulator about the airport management. if you want I can explain.
     
  5. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    Well, the program executed in the screen is ./projecto2ED, the first thing we see is a complain over pause: command not found

    ----------

    Is it actually an executable binary? Try this:

    Code:
    file projeto2ED
    
     
  6. miguel747 thread starter macrumors newbie

    Joined:
    Sep 25, 2011
    #6
    the problem in new code dont show anymore:

    see it

    http://img59.imageshack.us/img59/7083/capturadetela20110925s1.png

    [],

    ----------

    file lista1
    lista1: Mach-O 64-bit executable x86_64
     
  7. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #7
  8. miguel747 thread starter macrumors newbie

    Joined:
    Sep 25, 2011
    #8
    -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.
     
  9. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #9
    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.
     
  10. miguel747 thread starter macrumors newbie

    Joined:
    Sep 25, 2011
    #10
    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. :(
     
  11. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #11
    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.
     
  12. miguel747 thread starter macrumors newbie

    Joined:
    Sep 25, 2011
    #12
    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.
     

    Attached Files:

  13. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #13
    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.
     

Share This Page