Advertisement
paulogp

printf

Jul 18th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. // title: printf
  2. // ide: apple xcode
  3. // author: paulogp
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. int main (int argc, const char * argv[])
  9. {
  10.     char *the_name;
  11.     char the_buffer[255];
  12.     char the_buffer2[255];
  13.     int the_num;
  14.     float the_float;
  15.    
  16.     // output do simbolo "
  17.     printf("ola ou \"hello\"\n");
  18.     printf("\n");
  19.    
  20.     // output do simbolo %
  21.     printf("analise a 100%%\n");
  22.     printf("\n");
  23.    
  24.     // utilizacao de vars
  25.     the_name = "oki";
  26.     the_num = 99;
  27.     the_float = 3.1415926535897932384626433832795;
  28.     printf("output string: %s | inteiro: %i | duas casas significativas: %.2f\n", the_name, the_num, the_float);
  29.     printf("\n");
  30.    
  31.     // indentacao
  32.     the_name = "celulas (media de vida)";
  33.     the_num = 120;
  34.     printf("%35s %15i\n", the_name, the_num);
  35.     printf("\n");
  36.    
  37.     // formatacao usando constante string
  38.     the_name = "zebra";
  39.     printf("a %s tem %s\n", the_name, "riscas");
  40.     printf("\n");
  41.    
  42.     // formatacao usando constante operacao inteira
  43.     the_name = "resultado";
  44.     printf("o %s de 7 + 5 e %i\n", the_name, (7 + 5));
  45.     printf("\n");
  46.    
  47.     // copia constante para a var the_buffer
  48.     memcpy (the_buffer, "texto de exemplo salta para a variavel\n", sizeof(the_buffer));
  49.     printf("%s\n", the_buffer);
  50.    
  51.     // faz output de parte de string pelo "metodo de copia"
  52.     for (int i = 9; i < sizeof(the_buffer); ++i)
  53.         the_buffer2[i-9] = the_buffer[i];
  54.    
  55.     printf("%s\n", the_buffer2);
  56.    
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement