Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX 10 // Espécie de constante
- char str[MAX]; // Váriavel Global
- // Troca a palava-chave char por string[80]
- typedef char string[80];
- int count = 0;
- // Essa função envia um vetor por parametro.
- print_Array(void)
- {
- int numbers[10] = {4,3,2,1,5,6,7,8,9,0};
- int length = sizeof(numbers) / sizeof(numbers[0]);
- receive_Array(numbers, length);
- }
- // Essa função recebe um vetor por argumento sendo(matriz, tamanho da matriz)
- receive_Array(int *args, int arg)
- {
- int i;
- for(i = 0; i < arg; i++){
- printf("%d\n", args[i]);
- }
- }
- // Padrão de MENUS.
- void menu(){
- int menu_Option = 0;
- printf("\nPlease choose a Option:\n");
- scanf("%d", &menu_Option);
- switch(menu_Option)
- {
- case 0:
- //implement.
- break;
- case 1:
- //implement.
- break;
- default:
- printf("Please input a valid option!\n");
- break;
- }
- }
- // Contagem de números 1 a 10 com ','.
- void count_Num()
- {
- int i;
- for(i = 0; i <= 10; i++)
- {
- printf("%d", count);
- if(i == 10) break;
- count++;
- putchar(',');
- }
- putchar('.');
- printf("\n");
- count = 0;
- }
- int increm()
- {
- {
- static int i = 0; // static Value is salved in all calls.
- i++;
- return i;
- }
- }
- // Função para armazenar um valor em uma string.
- void input(void)
- {
- printf("Enter with a name:");
- fgets(str ,sizeof(MAX),stdin);
- fflush(stdin);
- fgets(str ,sizeof(MAX),stdin);
- printf("%s\n", str);
- }
- // Espécie de Menu sem switch.
- void f (void)
- {
- int t;
- string s; /* This is created only in cube enter. */
- while(t != 1)
- {
- printf("Please input a option:");
- scanf("%d", &t);
- fflush(stdin); // Clean the read buffer.
- if(t == 1)
- {
- input();
- }
- else
- {
- printf("Enter with option 1.");
- }
- }
- }
- // Verificar se existe um caractere na palavra.
- is_in(char *s, char c)
- {
- while(*s){
- if(*s == c) return 1; // Check if contains char on char*(string).
- else *s++;
- }
- return 0;
- }
- call_is_in(void)
- {
- char *str = "Word";
- char c = 'W';
- int ret = is_in(str,c);
- if(ret == 1) printf("true\n");
- else printf("false\n");
- }
- // Uma função de deixar um argumento como constante.
- void sp_to_dash(const char *str);
- void sp_to_dash(const char *str) // Sobreescrevi o método anterior.
- {
- while(*str)
- {
- if(*str == '-') printf("%c", ' ');
- else printf("%c", *str);
- str++;
- }
- printf("\n");
- }
- // Método main, ele é a rotina principal, o programa inicia por ele.
- int main (void)
- {
- sp_to_dash("Raphael-Santana-Carvalho");
- printf("Press a key to exit!...");
- getchar(); // Wait to any key.
- return 0;
- }
- // Trabalhando com ponteiros.
- // Work with pointers:
- /*int *pX;
- int x = 3;
- pX = &x;
- printf("Print the variable value: %d \n", *pX);
- printf("Print the address value input in pointer %p\n", &pX);
- printf("Print the pointer address: %p\n", pX);
- int *pY;
- int y = 3;
- pY = &y;
- printf("\nrint the variable value: %d \n", *pY);
- printf("Print the address value input in pointer %p\n", &pY);
- printf("Print the pointer address: %p\n", pY);
- *pY = *pX;
- printf("\nVariable Y receive value of X: %d \n", *pY);
- */
- //-------- ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement