程序代码:
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<stdio.h>
#include<string.h>
#include<stdlib.h>
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
运行结果:
程序代码:
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
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<len)
{
char t=*(p+i);
*(p+i)=*(p+len);
*(p+len)=t;
i++;
len--;
}
i=0;
//单个单词逆置
while(*(p+i))
{
int j=i;
while(*(p+j)!=' '&& *(p+j)!='\0')
{
j++;
}
len=j-1;
while(i<len)
{
char t=*(p+i);
*(p+i)=*(p+len);
*(p+len)=t;
i++;
len--;
}
while(*(p+j)==' ')
{
j++;
}
i=j;
}
puts(str);
return 0;
}
运行结果: