....

2014年5月25日 星期日

[長知識] C語言 - 新手篇章 - 字串、指標應用

#include <stdio.h>
#include <stdlib.h>
#define MAX 1024 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
//  字串、指標應用
//  java的String 是假字串,都是用字元陣列接的
int i;
char str[MAX];
printf("請輸入一段文字吧~");
gets(str);


// 指向陣列的起始位置
char *ptr = str;
// strlen字串長度
for(i =0; i<strlen(str); i++){
printf("%c", *(ptr+i));
}

return 0;
}

沒有留言:

張貼留言