Advertisement
mateuspl

gifnass() resolved

Jan 16th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int *gifnass(char str[], int lim) {
  6.     int strSize = strlen(str),
  7.         atualg = 0,
  8.         times = 0,
  9.         a,
  10.         *got = (int *) calloc(1, sizeof(int));
  11.     char alg[lim];
  12.    
  13.     for (a = 0; a < (strSize + 1); a++) {
  14.         if (str[a] != ' ') {
  15.             alg[atualg] = str[a];
  16.             atualg++;
  17.         }
  18.         if ((str[a] == ' ' || str[a] == '\0') && atualg != 0) {
  19.                 if (times != 0) {
  20.                     got = realloc(got, (times + 1) * sizeof(int));
  21.                 }
  22.                 alg[atualg] = '\0';
  23.                 sscanf(alg, "%d", &got[times]);
  24.                 times++;
  25.                 atualg = 0;
  26.         }
  27.     }
  28.     return(got);
  29. }
  30.  
  31. int main() {
  32.     char *str;
  33.     str = "10 20 30 40";
  34.     int *v;
  35.     v = gifnass(str, 3);
  36.     printf("%d %d %d %d \n\n", v[0], v[1], v[2], v[3]);
  37.    
  38.     system("pause");
  39.     return(0);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement