Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apple Xcode
- #include <stdio.h>
- #include <stdlib.h>
- // funcao
- void minha_divisao(int the_quocient, int the_div, int *the_result_div, int *the_result_rest)
- {
- *the_result_div = the_quocient / the_div;
- *the_result_rest = the_quocient % the_div;
- }
- // main
- int main (int argc, const char * argv[])
- {
- if (argc == 3)
- {
- char *the_temp; // guarda o que nao consegue converter
- // strtol obtido a partir do terminal ./nome_programa var1 var2
- int the_quocient = strtol(argv[1], &the_temp, 0); // strtol(argv[1], NULL, 0);
- int the_div = strtol(argv[2], &the_temp, 0); // strtol(argv[2], NULL, 0);
- int the_result_div;
- int the_result_rest;
- if (the_div != 0)
- {
- minha_divisao(the_quocient, the_div, &the_result_div, &the_result_rest);
- printf("div = %i\n", the_result_div);
- printf("resto = %i\n", the_result_rest);
- }
- } else {
- printf("inseridos %i, 2 valores necessarios!\n", argc-1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement