> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
