添加getSum
This commit is contained in:
		@@ -19,5 +19,5 @@
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "initializeCommand": "gdb -ex 'set confirm off' -ex quit",  // 初始化GDB配置
 | 
			
		||||
    "postAttachCommand": "make debug"  // 假设你的Makefile有debug目标
 | 
			
		||||
    "postAttachCommand": "make debug"  
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
			
		||||
include ./make.h
 | 
			
		||||
 | 
			
		||||
# 目标和源文件  
 | 
			
		||||
TARGETS  = fork execlp  
 | 
			
		||||
TARGETS  = fork execlp  getSum
 | 
			
		||||
SOURCES  = $(wildcard $(SRC_DIR)/*.c)  # 找到所有的 .c 文件  
 | 
			
		||||
OBJECTS  = $(patsubst $(SRC_DIR)/%.c,%.o,$(SOURCES)) # 将 .c 替换为 .o  
 | 
			
		||||
 | 
			
		||||
@@ -26,6 +26,9 @@ fork: fork.o
 | 
			
		||||
execlp: execlp.o  
 | 
			
		||||
	$(CC) -o execlp execlp.o  
 | 
			
		||||
 | 
			
		||||
getSum: getSum.o
 | 
			
		||||
	$(CC) -o getSum getSum.o
 | 
			
		||||
 | 
			
		||||
# 从 .c 文件编译生成 .o 文件  
 | 
			
		||||
%.o: $(SRC_DIR)/%.c  
 | 
			
		||||
	$(CC) $(CFLAGS) $(COMMON_INCLUDE_DIRS) -c $< -o $@  
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								src/getSum.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/getSum.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int getSum(void)
 | 
			
		||||
{
 | 
			
		||||
    int sum = 0;
 | 
			
		||||
    for (int i = 1; i <= 100; ++i) {
 | 
			
		||||
        sum += i;
 | 
			
		||||
    }
 | 
			
		||||
    return sum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main(void)
 | 
			
		||||
{           
 | 
			
		||||
    printf("%d\n", getSum());
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user