This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <arpa/inet.h> | |
| #include <locale.h> | |
| int main() { | |
| setlocale(LC_ALL, ""); // รองรับพิมพ์ภาษาไทย | |
| int sockfd; | |
| struct sockaddr_in servaddr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <arpa/inet.h> | |
| #include <locale.h> | |
| int main() { | |
| setlocale(LC_ALL, ""); // ให้ printf แสดง UTF-8 ได้ | |
| int sockfd; | |
| struct sockaddr_in servaddr, cliaddr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| // ประกาศฟังก์ชัน iterateArray ที่รับอาร์เรย์และฟังก์ชัน callback เป็นพารามิเตอร์ | |
| void iterateArray(void* array, int length, size_t size, void (*callback)(void*, int)) { | |
| for (int i = 0; i < length; i++) { | |
| callback(array + i * size, i); | |
| //callback (array[i], i); //ผิดไม่สามารถแบบนี้ได้ เพราะเป็น void* | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| // ฟังก์ชันสำหรับสลับค่าของสองตัวแปร | |
| void swap(int *xp, int *yp) { | |
| int temp = *xp; | |
| *xp = *yp; | |
| *yp = temp; | |
| } | |
| // ฟังก์ชันสำหรับ Bubble Sort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| typedef struct Node { | |
| char name[100]; // สมมติว่าชื่อมีความยาวสูงสุด 100 ตัวอักษร | |
| struct Node* next; | |
| } Node; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <glib.h> | |
| int main() { | |
| GArray *name_array = g_array_new(TRUE, FALSE, sizeof(char *)); // สร้าง GArray สำหรับเก็บ pointer ไปยังสตริง | |
| g_print("Enter names (press Enter without input to stop):\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| int main() { | |
| char **name = NULL; // ประกาศ pointer ไปยัง array ของ pointer ที่เก็บสตริง | |
| int size = 0; // จำนวนสมาชิกใน array name | |
| char buffer[100]; // เก็บข้อมูลที่ผู้ใช้ป้อน | |
| printf("Enter names (press Enter without input to stop):\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Example program demonstrating the functionality of GtkTreeView and the usage of GArray. | |
| * Compile: gcc -g -o ex_treeview ex_treeview.c `pkg-config --cflag --libs gtk+-3.0` | |
| */ | |
| #include <gtk/gtk.h> | |
| typedef struct { | |
| gint index; | |
| gchar *item; | |
| gchar *path; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <gtk/gtk.h> | |
| static void activate(GtkApplication *app, gpointer user_data) { | |
| // Create a new toplevel window | |
| GtkWidget *window = gtk_application_window_new(app); | |
| gtk_window_set_title(GTK_WINDOW(window), "GtkListBox Example"); | |
| gtk_window_set_default_size(GTK_WINDOW(window), 300, 200); | |
| // Create a GtkListBox | |
| GtkWidget *listbox = gtk_list_box_new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * This example very simple to use Gtk for beginers | |
| * in the past I used this style to coding but now, | |
| * I use Glade to generate ui file to display GUI | |
| * it's very easy to manipulate layout of the widgets | |
| */ | |
| #include <gtk/gtk.h> | |
| typedef struct _MyWidgets { | |
| GtkWidget *window; |
NewerOlder