2.8作业

2.8作业_第1张图片

程序代码:

CC=gcc
EXE=hello
OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
CFLAGS=-c -o
 
all:$(EXE)
 
$(EXE):$(OBJS)
	$(CC) $^ -o $@
 
%.o:%.c
	$(CC) $(CFLAGS) $@ $^
 
.PHONY:clean
 
clean:
	@rm $(OBJS) $(EXE)

程序代码:

#include
#include
#include

int main(int argc, const char *argv[])
{
	char a[100]="";
	printf("please input string:");
	gets(a);
	int i=0,count=0;
	while(a[i]!='\0')
	{
		if(a[i]==' ')
			count++;
		i++;
	}
	printf("%d\n",count+1);
	

	return 0;
}

运行结果:

程序代码:

#!/bin/bash
read -p "please enter file:" file
 
if [ -b $file ]
then
	echo dev

elif [ -c $file ]
then
	echo char_dev

elif [ -d $file ]
then
	echo dir

elif [ -L $file ]
then 
	echo link

elif [ -S $file ]
then
	echo socket

elif [ -p $file ]
then
	echo pipe

elif [ -f $file ] 
then
	echo regular

else
	echo error
fi
 

运行结果:

2.8作业_第2张图片

程序代码:

#include
#include
#include

int main(int argc, const char *argv[])
{
	char str[100]="";
	printf("please input string:");
	gets(str);
	char *p=str;
	int len=strlen(p)-1;
	int i=0;

	//整体逆置
	while(i

运行结果:

你可能感兴趣的:(linux,运维,服务器)