#include <stdio.h>
#include <string.h>
#define NAME_LEN 25
void listNames(int PEOPLE, char Lname[][NAME_LEN]);
void printNames(int PEOPLE, char Lname[][NAME_LEN]);
void getName(char name[]);
int main(void)
{
int PEOPLE = 10;
int member = 0;
char name[NAME_LEN];
char Lname[PEOPLE][NAME_LEN];
listNames(PEOPLE, Lname);
printNames(PEOPLE, Lname);
return 0;
}
void listNames(int PEOPLE, char Lname[][NAME_LEN])
{
int i;
for (i = 0; i < PEOPLE; i++)
{
printf("Enter name: ");
scanf("%[^\n]", Lname[i]);
getchar();
}
}
//Displays the names//
void printNames(int PEOPLE, char Lname[][NAME_LEN])
{
int i;
printf("\nList of names:\n");
for (i = 0; i < PEOPLE; i++)
{
printf("Names: %-15s\n", Lname[i]);
}
}
显示它们后,我不知道如何更改已经输入的名称。
最佳答案
你的意思是基于索引的变化。
int idx = 0 ;
for( ; idx < PEOPLE; idx ++ ) {
sprintf( Lname[idx], "%s", "New LName");
}
或根据名称本身进行更改?
int idx = 0 ;
for( ; idx < PEOPLE; idx ++ ) {
if( strcmp( Lname[idx], "OriginalName") == 0 ) {
sprintf( Lname[idx], "%s", "New LName");
break;
}
}
关于c - 显示名称后如何更改我输入的名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47159717/