#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]);
}
}
我不知道如何更改显示后输入的名称。
答案 0 :(得分:0)
你的意思是基于索引的变化。
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;
}
}