0

I am trying to run c in xcode 6,however I run the ⌘R it shows build Succeeded but nothing in console,but I can run it in ubuntu Linux's gcc,here is my c code in ubuntu Linux

#include <stdio.h>
int main()
{
int a[100],i,j,t,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n-1;i++)
{
    for(j=1;j<=n-i;j++)
    {
        if(a[j]<a[j+1])
        { t=a[j]; a[j]=a[j+1]; a[j+1]=t; }
    }
}
for(i=1;i<=n;i++)
    printf("%d ",a[i]);

getchar();getchar();
return 0;

}

when I run it in gcc it's ok,

ubuntu#vi ac9.c
ubuntu#gcc -o ac9 ac9.c
ubuntu#./ac9

the file name is ac9.c

but move it to mac's xcode ,I run the ⌘R it shows build Succeeded but nothing in console, and here is my code in xcode 6.4

enter image description here

Joe Lin
  • 613
  • 2
  • 11
  • 33

2 Answers2

1

You probably need to signal to the Operating System to dump what is in the output buffer to the screen before the calls to getchar().

The easiest way to do that is to print a newline.

// ...
// print a newline; force OS to dump output buffer
printf("\n"); // or puts("");
getchar(); getchar();
// ...

One other way is to call fflush()

// ...
// force OS to dump output buffer
fflush(stdout);
getchar(); getchar();
// ...
pmg
  • 106,608
  • 13
  • 126
  • 198
0

From Xcode not showing anything in console with C++,

Your image doesn't show that you ran the program, only that you built it. Look at the Log Navigator (the last one, ⌘7) and see if there are any logs for 'Debug one' after 'Build one'. To run the program use Product > Run or ⌘R.

Community
  • 1
  • 1
Liyuan Liu
  • 172
  • 2
  • I run the ⌘R it shows build Succeeded but nothing is console – Joe Lin Jul 26 '15 at 09:58
  • see this link:http://stackoverflow.com/questions/9576258/xcode-not-showing-anything-in-console-with-c – Liyuan Liu Jul 26 '15 at 10:02
  • When you copy someone else's answer, make sure you link to it and quote the copied text, otherwise you're plagiarizing them. –  Oct 01 '15 at 01:45