c - Unknown error regarding strings and stdio.h library -
i'm receiving uknown error found in stdio.h library. please can check @ tell me wrong code (but thing should work fine). p.s. i'm new here please don't blame me if bad question. code:
#include <stdio.h> #include <stdlib.h> // conversion number string char *i2s(int broj); int main() { char string1; int br, n; { printf("how numbers?\n -"), scanf("%d", &n); } while (n < 1); (int = 0; < n; i++) { printf("\nbr = "), scanf("%d", &br); string1 = *i2s(br); printf(" %s", string1); } free(string1); getch(); return 0; } char *i2s(int broj) { char *pom; int z=0,br=0,p; if (broj < 0) { z = 1; broj = -broj; } p = broj; { br++; p /= 10; } while (p); pom = (char *)calloc(br + 1 + z, sizeof(char)); if (z) pom[0] = '-'; { pom[--br + z] = '0' + broj % 10; } while (broj /= 10); return pom; }
char string1; free(string1); string 1 not pointer.
also following section overwrite string1 everytime run through loop. way have no pointer free() memory allocate inside function unless inside loop.
for (int = 0; < n; i++) { printf("\nbr = "), scanf("%d", &br); string1 = *i2s(br); printf(" %s", string1); }
Comments
Post a Comment