User Tools

Site Tools


cplusplus:c_examples

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cplusplus:c_examples [2019/04/23 01:31] – [File access] mithatcplusplus:c_examples [2020/12/07 02:40] (current) – [C Examples] mithat
Line 1: Line 1:
 ====== C Examples ====== ====== C Examples ======
-adapted from \\ +Mithat Konar \\  
-**Differences Between C and C++** \\ +Derived from //**Differences Between C and C++**// by Robert Niemann \\ 
-by Robert Niemann (Century College) \\ +2020-05-03
-11/22/2015+
  
 ===== Input/output ===== ===== Input/output =====
  
   * [[http://www.cplusplus.com/reference/cstdio/printf/ | printf() reference]]   * [[http://www.cplusplus.com/reference/cstdio/printf/ | printf() reference]]
-  * [[http://www.cplusplus.com/reference/cstdio/sprintf/ | scanf() reference]]+  * [[http://www.cplusplus.com/reference/cstdio/scanf/ | scanf() reference]] 
 + 
 + 
 +<file c example00.c> 
 +/* Basic printf use. */ 
 +#include <stdio.h> 
 + 
 +int main() 
 +
 +  int numSpoons = 5; 
 + 
 +  printf( "I have %d spoons.\n", numSpoons ); 
 +   
 +  return 0; 
 +
 +</file>
  
 <file c example01.c> <file c example01.c>
 +/* Basic scanf use. */
 #include <stdio.h> #include <stdio.h>
  
Line 19: Line 34:
     printf( "Please enter a number: " );     printf( "Please enter a number: " );
     scanf( "%d", &num );     scanf( "%d", &num );
-    printf( "You entered %d", num );+    printf( "You entered %d\n", num );
  
     return 0;     return 0;
Line 26: Line 41:
  
 <file c example02.c> <file c example02.c>
 +/* Common I/O format specifiers. */
 #include <stdio.h> #include <stdio.h>
  
Line 42: Line 58:
  
 <file c example03.c> <file c example03.c>
 +/* More I/O format specifiers. */
 #include <stdio.h> #include <stdio.h>
  
Line 94: Line 111:
 { {
     FILE *ptr_file;     FILE *ptr_file;
-    char buf[1000];+    char buf[1000];    /* can store strings up to 999 chars long */
  
     ptr_file = fopen("input.txt","r");     ptr_file = fopen("input.txt","r");
cplusplus/c_examples.1555983063.txt.gz · Last modified: 2019/04/23 01:31 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki