Hello. There were difficulties in solving. The elements of an "unlimited" array are introduced. It is planned to output all elements ( char / int ) of the array, but displays other characters similar to alt codes. In the table Ascii I did not find ♫. How do I solve this problem?
#include <stdio.h> #include <stdlib.h> #include <mem.h> int main() { int i; char* string = (char*) malloc(sizeof(char)); char c; printf("Enter your number:\n"); for (i = 0; (c = getchar()) == '\n'; i++) { if (string == NULL) { string = (char*) malloc(i + 2); } else { string = (char*) realloc(string, i + 2); } string[i] = c; string[i + 1] = '\0'; } for (i = 0; i < strlen(string); i++) { printf("a[%c]\n", string[i]); } free(string); system("pause"); return 0; } //a[` == 96] //a[♫ == 14] //a[u == 117]
getchar()returns anint. No need to store the result inchar. - Ternvein