【寒假作业】day2.8

1.

CC=gcc
EXE=a.out
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)

2.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int main(int argc, const char *argv[])
{
	char str[50]="";
	printf("please enter str:");
	gets(str);
	int num=0;
	char c;
	for(int i=0;str[i]!='\0';i++)
	{
		if(str[i]==' '){
			num++;
		}
	}
	printf("%d\n",num+1);
	return 0;
}

3.

#!/bin/bash 
read -p "please enter file:" file  
if [  -b ./$file ]     
then
    echo block
elif [ -c ./$file ]   
then
    echo character
elif [ -d ./$file ] 
then
    echo directory
elif [ -f ./$file ]  
then
    echo file
elif [ -L ./$file ]  
then
    echo line
elif [ -S ./$file ]    
then
    echo socket
elif [ -p ./$file ]
then
    echo pipe
else
    echo unexist               
fi

4.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
	char str[30]="";
	printf("please enter str:");
	gets(str);
	int i=0,j=0;
	while(str[i]!='\0')
	{
		if(str[i]!=' ')
        {
			str[j]=str[i];
		}
		j++;
		i++;
	}
	str[j]='\0';
	puts(str);
	i=0,j=strlen(str)-1;
	while(i<j)
	{
		char t=str[i];
		str[i]=str[j];
		str[j]=t;
		i++;
		j--;
	}
	i=j=0;
	while(str[i]!='\0')
	{
		while(str[j]!=' ' && str[j]!='\0')
		{
			j++;
		}
		int k=j-1;//保存j-1的下标
		while(i<k)//字符串逆置
		{
			char t=str[i];
			str[i]=str[k];
			str[k]=t;
			i++;
			k--;
		}
		while(str[j]==' ')
		{
			j++;
		}
		i=j;
	}
	puts(str);
 
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值