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

1
  • please post code, not pictures of code…
    – Beat
    Commented Jul 26, 2015 at 9:31

2 Answers 2

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();
// ...
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.

3
  • I run the ⌘R it shows build Succeeded but nothing is console
    – Joe Lin
    Commented Jul 26, 2015 at 9:58
  • see this link:stackoverflow.com/questions/9576258/…
    – Liyuan Liu
    Commented Jul 26, 2015 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.
    – user456814
    Commented Oct 1, 2015 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.