在AIX机器上的C程序
【checkpass.c】
#include <stdio.h>
#include <string.h>
int checkpass(void){
int x;
char a[9];
x = 0;
fprintf(stderr,"a at %p and\nx at %p\n", (void *)a, (void *)&x);
printf("Enter a short word: ");
scanf("%s", a);
if (strcmp(a, "mypass") == 0)
x = 1;
return x;
}
[make.c]
#include <stdio.h>
int checkpass(void);
int main(void)
{
int x;
x = checkpass();
fprintf(stderr, "x = %d\n", x);
if (x)
fprintf(stderr, "Password is correct!\n");
else
fprintf(stderr, "Password is not correct!\n");
return 0;
}
[makefile]
LINT = lint ## lint check Code
LOPS = -x #-u
CC = cc #xlc ## 注意:大写'C' for c++
CC_FLAGS = #-q64 #-bnoquiet
INCLUDE= #-I. -I/usr/include -I/usr/vacpp/include
LIBPATH=#-L/usr/vacpp/lib -L/usr/lib -L/lib
PROGRAM = run
ALL : $(PROGRAM)
.SUFFIXES: .cpp .c .cc .cxx .o
.DEFAULT : all
SRCS = main.c checkpass.c
OBJS = $(SRCS:.c=.o)
$(PROGRAM) : $(OBJS)
$(CC) $(CC_FLAGS) $(INCLUDE) $(LIBPATH) $(OBJS) -o $(PROGRAM)
.c.o:
$(CC) $(INCLUDE) $(CC_FLAGS) -c $<
lintall: lint
lint:
$(LINT) $(LOPS) main.c checkpass.c
clean:
- rm -f ./*.o ./*.a ./$(PROGRAM)
[end]
相关文档:
1.已知strcpy 函数的原型是:
char *strcpy(char *strDest, const char *strSrc);
其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy
答案:
char *strcpy(char *strDest, const char *strSrc)
{
if ( strDest == NULL || strSrc == NULL)
return NULL ;
if ( strDest ......
操作系统的一个经典问题是"生产者-消费者"问题, 这涉及同步信号量和互斥信号量的应用, 在这里,我用线程的同步和互斥来实现.
/*
* author 张文
* 2008/06/20
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h> ......
#include <stdio.h>
#define N 19
int main()
{
int i;
for (i=0;i<=N;i++)
{
printf("%*.*s%-*.*s\n",N,i<=N/2?i:N-1,"*******************",\
N,i<=N/2?i+1:N-i+1,"*******************");
}
return 0;
}
%m.ns ......
char a[10];
怎么给这个数组赋值呢?
1、定义的时候直接用字符串赋值
char a[10]="hello";
注意:不能先定义再给它赋值,如char a[10]; a[10]="hello";这样是错误的!
2、对数组中字符逐个赋值
char a[10]={'h','e','l','l','o'};
3、利用strcpy
char a[10]; strcpy(a, "hello");
易错情况:
1、char a[1 ......