Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
main.c File Reference

Entry point for the application. Parses command-line arguments and either starts the HTTP server or fetches and displays a GitHub user. More...

#include "server.h"
#include "user.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Main function that initializes and runs the application.
 

Detailed Description

Entry point for the application. Parses command-line arguments and either starts the HTTP server or fetches and displays a GitHub user.

Definition in file src/main.c.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Main function that initializes and runs the application.

Supported command-line arguments:

  • --user <username> : Specify the GitHub username to fetch.
  • --user=<username> : Alternative way to specify the GitHub username.
  • --server : Run the HTTP server instead of fetching a user.
  • --port=<port> : Specify the port for the HTTP server (default: 1234).
Parameters
argcArgument count.
argvArgument vector.
Returns
int Exit status code (0 for success, nonzero for failure).

Definition at line 27 of file src/main.c.

27 {
28 const char *username = "izelnakri";
29 int port = 1234;
30 int run_server = 0;
31
32 for (int i = 1; i < argc; i++) {
33 if (strcmp(argv[i], "--user") == 0 && i + 1 < argc) {
34 username = argv[i + 1];
35 i++;
36 } else if (strncmp(argv[i], "--user=", 7) == 0) {
37 username = argv[i] + 7;
38 } else if (strcmp(argv[i], "--server") == 0) {
39 run_server = 1;
40 } else if (strncmp(argv[i], "--port=", 7) == 0) {
41 char *endptr = NULL;
42 port = (int)strtol(argv[i] + 7, &endptr, 10);
43 if (endptr == argv[i] + 7 || *endptr != '\0') {
44 (void)fprintf(stderr, "Invalid port number: %s\n", argv[i] + 7);
45 exit(EXIT_FAILURE);
46 }
47 }
48 }
49
50 if (run_server) {
52 } else {
53 User user = fetch_github_user(username);
54 print_github_user(&user);
55 }
56
57 return 0;
58}
#define NULL
Definition gmacros.h:924
void start_http_server(int port)
Starts an HTTP server on the specified port.
Definition server.c:59
Structure representing a GitHub user.
Definition user.h:9
void print_github_user(const User *user)
Print a User's information to the console.
Definition user.c:230
User fetch_github_user(const char *username)
Fetch a GitHub user's information via the GitHub API.
Definition user.c:130

References fetch_github_user(), NULL, print_github_user(), and start_http_server().