# 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 เพื่อตรวจสอบว่าไฟล์ที่คอมไพล์แล้วสามารถออกมาได้หรือไม่

![](https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MClo3nC-1US0rbK8Qau%2F-MP2WKtPztKM8lqzIamh%2F-MP2XBvWXEDGD2BDP8_H%2Fimage.png?alt=media\&token=9bf53a87-4c61-42c6-bba7-6f30d63ea7b7)

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
