在此代码中,我将用户输入的用户名存储在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 . . .
答案 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