# How to create a program that you can enter inputs.

### 1.การรับ Input หลังจากรันโปรแกรม

1.1 ไปที่แถบเมนูของโปรแกรม Virtual studio code ที่ file เลือก New File สร้างไฟล์ชื่อว่า\
&#x20;      myname.c ขึ้นมา

1.2 ทำการ copy code ด้านล่างลงไปแล้วทำการ save (ctrl + s) โปรแกรมที่เขียนไว้

```c
#include <stdio.h>
#include <string.h>

int main(void) {
  char name[50] = "";
  char lastname[50] = "";
  printf("Please enter your name\n");
  scanf("%s",name );
  printf("Please enter your lastname\n");
  scanf("%s",lastname );
  printf("your name is %s %s\n", name, lastname);
  return 0;
}
```

1.3 ไปยัง terminal ใช้คำสั่ง gcc เพื่อ complie โปรแกรมที่เขียนออกมา

```c
gcc myname.c -o myname
```

1.4 ใช้คำสั่ง ls เพื่อตรวจสอบว่าไฟล์ที่คอมไพล์แล้วสามารถออกมาได้หรือไม่

![](/files/-MP2XBvWXEDGD2BDP8_H)

1.5 ลอง run โปรแกรมที่เขียนโดยใช้คำสั่ง ./ชื่อโปรแกรม

```
./myname
```

* ทำการบันทึกผลการรันโปรแกรมทีละขั้นตอน โดยใส่ Input ทั้งหมดเข้าไป

### 2.การรับ Input ขณะเรียก program

1. สร้าง workspace ใน Linux command และเปิดด้วยคำสั่ง

```c
code ./[workspace created]
```

2\. สร้างไฟล์ใหม่และ Copy โค้ดด้านล่างใส่ใน Visual Studio Code&#x20;

```c
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("%d\n",argc);
    printf("%s\n",argv[0]);
    printf("%s\n",argv[1]);
    printf("%s\n",argv[2]);
    printf("address first argument is 0x%lx\n",(long)&argv[1]);
    printf("address second argument is 0x%lx\n",(long)&argv[2]);
    return 0;
}
```

3\. ทำการ save ชื่อว่า argument.c ไฟล์และ Compile โค้ดดังกล่าวดัวยคำสั่ง

```c
gcc argument.c -o arg
```

4\. ทำการรันทดสอบโปรแกรม

```c
./arg 11
./arg 54 43
./arg 24 69 420
```

* ทำการบันทึกผลการรันโปรแกรมทีละขั้นตอน อธิบายที่มาของ output


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/principle-c-c++-programming/linux-os-lab-1-c-c++-code.-how-to-compile-and-run./how-to-create-a-program-that-you-can-enter-inputs..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
