Skip to content

Lab 5 git #6

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

Open
wants to merge 2 commits into
base: main
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
1 change: 1 addition & 0 deletions f74101335/lab_2_git/first.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
first text
9 changes: 9 additions & 0 deletions lab_5_F74101335/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore the build and lib dirs
build
lib/*

# Ignore any executables
bin/*

# Ignore temporary files
*.swp
29 changes: 29 additions & 0 deletions lab_5_F74101335/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CC := gcc
SRCDIR := src
BUILDDIR := build
BINDIR := bin
INCDIR := include
TARGET := $(BINDIR)/runner

SRCEXT := c
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
HEADERS := $(shell find $(INCDIR) -type f -name *.h)
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
CFLAGS := -O2 -Wall

all: $(TARGET)

$(TARGET): $(OBJECTS)
mkdir -p $(BINDIR)
@echo "> Linking..."
$(CC) $^ -o $(TARGET)


$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
mkdir -p $(BUILDDIR)
@echo "> Compiling..."
$(CC) $(CFLAGS) -c -o $@ $<

clean:
@echo "> Cleaning...";
$(RM) -rf $(BUILDDIR) $(TARGET)
6 changes: 6 additions & 0 deletions lab_5_F74101335/include/strcpy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef STRCPY_H
#define STRCPY_H

char *sstrcpy(char *dest, const char *src);

#endif /*STRCPY_H */
10 changes: 10 additions & 0 deletions lab_5_F74101335/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "../include/strcpy.h"
int main(){
const char *src = "f74101335";
char *dest = malloc(10);
dest = sstrcpy(dest, src);
printf("%s\n", dest);
return 0;
}
12 changes: 12 additions & 0 deletions lab_5_F74101335/src/strcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "../include/strcpy.h"

char *sstrcpy(char *dest, const char *src)
{
//Input
int i = 0;
while(src[i] != '\0'){
dest[i] = src[i];
i ++;
}
return dest;
}