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)
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
int word(char *p)
{
int i=0,count=0;
while(*(p+i)==' ')
i++;
while(*(p+i)!='\0')
{
int j=i;
while(*(p+j)!=' ' && *(p+j)!='\0')
j++;
if(*(p+j)==' ')
count++;
while(*(p+j)==' ')
j++;
i=j;
}
return count+1;
}
int main(int argc, const char *argv[])
{
char str[40]="";
printf("please enter the str:");
gets(str);
int num=word(str);
printf("%d\n",num);
return 0;
}
#!/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
#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);
puts(str);
//整体逆置
int 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;
while(i<k)
{
char t=str[i];
str[i]=str[k];
str[k]=t;
i++;
k--;
}
while(str[j]==' ')
{
j++;
}
i=j;
}
i=j=0;
while(str[i]!='\0')
{
if(str[i]!=' ')
printf("%c",str[i]);
i++;
}
puts("");
return 0;
}