emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] C code block: no return values


From: Roger Mason
Subject: [O] C code block: no return values
Date: Tue, 16 Apr 2013 13:23:33 -0230
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130403 Thunderbird/17.0.5

Hello,

I'm working through examples in "A Multi-Language Computing Environment for
Literate Programming and Reproducible Research" by Shulte et al. J. Stat. Software, 46/3, 2012.

This example compiles but results are not returned to the Org-mode buffer:
========================================================
#+name: cocktail.c
#+begin_src C :noweb yes :tangle cocktail.c
#include <stdio.h>
<<cocktail-sort>>
<<main>>
#+end_src

#+name: main
#+begin_src C
int main(int argc, char *argv[]) {
int lst[argc-1];
int i;
for(i=1;i<argc;i++)
lst[i-1] = atoi(argv[i]);
sort(lst, argc-1);
for(i=1;i<argc;i++)
printf("%d ", lst[i-1]);
printf("\n");
}
#+end_src

#+name: cocktail-sort
#+begin_src C :noweb yes
void sort(int *a, unsigned int l)
{
int swapped = 0;
int i;
do {
for(i=0; i < (l-1); i++) {
<<swap>>
}
if ( swapped == 0 ) break;
swapped = 0;
for(i= l - 2; i >= 0; i--) {
<<swap>>
}
} while(swapped > 0);
}
#+end_src

#+name: swap
#+begin_src C
if ( a[i] > a[i+1] ) {
int temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
swapped = 1;
}
#+end_src

#+call: cocktail.c[:cmdline 8 7 6 3 2 4 78]()
===========================================

Running C-c on the "call" line above produces:

===============================
#+RESULTS: cocktail.c[:cmdline 8 7 6 3 2 4 78]()
================================

The answers should be here.  But they aren't.

Thanks for any help.

Roger

This electronic communication is governed by the terms and conditions at
http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2012.php



reply via email to

[Prev in Thread] Current Thread [Next in Thread]