User Tools

Site Tools


cs_lang:c

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
cs_lang:c [2011/07/12 10:48] – [Read a file] cedriccs_lang:c [2011/07/12 11:52] cedric
Line 30: Line 30:
 Hello World Hello World
 </code> </code>
 +
 +
 +===== Increment a number =====
 +<code c>
 +#include "stdio.h"
 +
 +char  line[100];
 +int   value;
 +
 +int main()
 +{
 +    printf("Enter a value:");
 +    fgets(line, sizeof(line), stdin);
 +    sscanf(line, "%d", &value);
 +
 +    printf("Inc: %d\n", value + 1);
 +    return value+1;
 +}
 +</code>
 +
 +<code bash>
 +$ gcc -Wall test1.c 
 +cedric@debian:~$ ./a.out 
 +Enter a value:41
 +Inc: 42
 +</code>
 +
 +==== Equivalent in python ====
 +<code python>
 +>>> def inc():
 +...     value = raw_input("Enter a value:")
 +...     print "Inc:", int(value)+1
 +... 
 +>>> inc()
 +Enter a value:41
 +Inc: 42
 +<code>
  
  
cs_lang/c.txt · Last modified: 2012/09/30 23:32 by cedric