#include<stdio.h> #include<ctype.h> void enter_num(char base_num[], int num); int main() { char base_num[7] = {}; enter_num(base_num, 7); printf("%c", base_num[1]); return 0; } void enter_num(char base_num[], int num) { int i; for ( i = 0; i < num; i++)//for user input,stop when input is blank { base_num[i] = getchar(); if (isspace(base_num[i])) { base_num[i] = '\0'; } if (isalnum(base_num[i])||base_num[i]=='\0')//Verify if the digital input is correct, if not, re-enter ; else { printf("The number is wrong!Please enter again.\n"); i = 0; } if (base_num[i] = '\0') { break; } } int n = 0; while (n < i)//Convert all input letters to lowercase { if (isalpha(base_num[n])) { base_num[n] = tolower(base_num[n]); } n++; } }
I tried to output the second array element, but I output blank space. And I need to output two line breaks to end the program.
Quote:And I need to output two line breaks to end the program.
printf("\n\n");
if (base_num[i] = '\0')
if (base_num[i] == '\0')
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)