Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more functionality #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

all: build run ## build and run the code


Expand All @@ -14,6 +13,13 @@ run: ## run the code
clean: ## removes generated directory & files
rm -rf bin

create_user_list: ## create a text file that contain all of the system user's
awk -F: '{ print $$1}' /etc/passwd >> bin/user.txt
@# remove last \n from user.txt file to prevent overprinting Hello in last line
truncate -s -1 bin/user.txt

hello_everyone: build create_user_list run ## saying hello to all user

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%s: %s\n", $$1, $$2}'

28 changes: 27 additions & 1 deletion src/hello_world.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#include <stdio.h>

int main() {
puts("Hello World!");
FILE *file;
if(file = fopen("bin/user.txt", "r"))
{
char c = fgetc(file);
// print Hello for first user
if(c != EOF)
{
printf("Hello ");
}
while (c != EOF)
{
// print Hello for other user
if (c == '\n' && c != '\0')
{
printf("\nHello ");
c = fgetc(file);
continue;
}
printf("%c",c);
c = fgetc(file);
}
fclose(file);
}
else
{
puts("Hello World!");
}
}