Hi
I keep getting segmentation fault when the program gets to
This is in another constructor, I have included the code and the output below, Please let me know if you know why I get segmentation fault when I use c[i] = c[i + 1]Code:c[i] = c[i + 1];
Code:#include <stdio.h> #include <string.h> class Account { char customer[251]; char accountNumber[16]; int balance; public: Account(); Account(char c[]); }; int main() { Account test(" test"); return 0; } Account::Account() { strcpy(customer, ",,,;"); strcpy(accountNumber, "000000000000000"); balance = 0; } Account::Account(char c[]) { int i = 0; //while loop removes the spaces in front of the string. while (c[i] == ' ' || c[i] == '\t' || c[i] == '\n') { printf("Loop started\n"); c[i] = c[i + 1]; i++; } }
Output
Loop started
Segmentation fault
Thank You



LinkBack URL
About LinkBacks





CornedBee