为什么这不能正确打印我输入的用户名?

时间:2019-06-11 23:30:27

标签: c

在此代码中,我将用户输入的用户名存储在struct的1-d数组中,但是当我打印此用户名时,它无法正确打印。

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct ng
{
    char username[32];
}ng;
void print();
int main()
{
    ng a;
    printf("Enter Username: ");
    scanf("%[^\n]%*c",a.username);
    print();
}
void print(void)
{
    ng a;
    printf("Username: %s",a.username);
}

输出:

在输出中,我输入“ George”,但无法打印。

Enter Username: Geroge
Username: 
--------------------------------
Process exited after 8.333 seconds with return value 0
Press any key to continue . . .

1 个答案:

答案 0 :(得分:1)

您有两个类型为def create @activity = Activity.new(activity_params) if params[:activity][:type_place_activity] == RoomEvent.name room_event = RoomEvent.find(params[:activity][:room_event][:id]) location_activity = LocationActivity.new location_activity.activity_place = room_event end location_activity.activity_id = @activity if @activity.save render json: {status: 'created', message: 'Activity save'} else render json: @activity.errors, status: :unprocessable_entity end end location_activities变量,每个函数一个。

您需要将a传递到ng中,例如:

main

并调用:

print