c - Converting integer to string with atoi/sprintf -
this not whole code sum easy see. have no problem convert string integer cannot convert integer string. program crashes. here code. @ line itoa.
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define sizex 49 #define sizey 6 int main() { size_t x, y; char *a[50][7]; char name[50][100]; char surname[50][100]; char in[50][100]; char yob[50][100]; char usname[50][100]; char pass[50][100]; char totamount[50][100]; (x = 0; x <= sizex; x++) { a[x][0] = name[x]; a[x][1] = surname[x]; a[x][2] = in[x]; a[x][3] = yob[x]; a[x][4] = usname[x]; a[x][5] = totamount[x]; a[x][6] = pass[x]; } printf("\nplease enter name of new user\n"); scanf(" %s", a[0][0]); printf("please enter surname of new user\n"); scanf(" %s", a[0][1]); printf("please enter identity number of new user\n"); scanf(" %s", a[0][2]); printf("please enter year of birth of new user\n"); scanf(" %s", a[0][3]); printf("please enter username of new user\n"); scanf(" %s", a[0][4]); strcpy(a[0][6], a[0][4]); strrev(a[0][6]); a[0][5] = "0"; int z; z = atoi(a[0][5]); z = z + strlen(a[0][4]) * 10; itoa(z, a[0][5], 10); //sprintf(a[0][5], "%d", z); printf("%s\n", a[0][5]); printf("%d\n", z); return 0; }
by doing this:
a[0][5]="0"; you assigning a[0][5] pointer readonly memory containing string literal "0".
here:
itoa( z, a[0][5],10 ); you attempting write there, giving memory access violation.
Comments
Post a Comment