Click here to Skip to main content
16,015,900 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#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++;
	}
}


What I have tried:

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.
Posted
Updated 1-May-23 2:24am

1 solution

Quote:
And I need to output two line breaks to end the program.
Well, that's easy:
C
printf("\n\n");


In C, "=" is an assignment:
C
if (base_num[i] = '\0')
What you need is a comparison:
C
if (base_num[i] == '\0')
 
Share this answer
 
v2
Comments
1beginner1 1-May-23 9:18am    
Thank you!
OriginalGriff 1-May-23 10:19am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900