Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int *gifnass(char str[], int lim) {
- int strSize = strlen(str),
- atualg = 0,
- times = 0,
- a,
- *got = (int *) calloc(1, sizeof(int));
- char alg[lim];
- for (a = 0; a < (strSize + 1); a++) {
- if (str[a] != ' ') {
- alg[atualg] = str[a];
- atualg++;
- }
- if ((str[a] == ' ' || str[a] == '\0') && atualg != 0) {
- if (times != 0) {
- got = realloc(got, (times + 1) * sizeof(int));
- }
- alg[atualg] = '\0';
- sscanf(alg, "%d", &got[times]);
- times++;
- atualg = 0;
- }
- }
- return(got);
- }
- int main() {
- char *str;
- str = "10 20 30 40";
- int *v;
- v = gifnass(str, 3);
- printf("%d %d %d %d \n\n", v[0], v[1], v[2], v[3]);
- system("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement