....

2014年5月25日 星期日

[長知識] C語言 - 新手篇章 - 字串

#include <stdio.h>
#include <stdlib.h>

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

int main(int argc, char *argv[]) {
// 字串String 為 字元陣列

char str[] = "Hello!";


// str[0]='H';
// str[1]='e';
// str[2]='l';
// str[3]='l';
// str[4]='o';
printf("BEFORE:%s\n", str);

strcpy(str, "OHYA!");

printf("AFTER:%s", str);


int i;

char name[][6]={"Mary", "Tony", "Steve", "傻子"};
for(i = 0; i<sizeof(name)/sizeof(name[0]); i++){
printf("\n%s", name[i]);
}

// printf("%d", sizeof('傻'));







return 0;
}

沒有留言:

張貼留言