我只想做一个记录,随机以C或D开头,并且有一个1-10的数字。所以一个记录将是C10。任何人都可以告诉我我在这里做错了什么?C字符串问题
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
/*
*
*/
int main(int argc, char** argv)
{
char letter[] = { 'C', 'D' };
char record[2];
int r=1;
while (r < 11)
{
char num;
num = r;
record = (letter[rand()%2],num);
r++;
}
return 0;
}
你得到了什么错误? – Johanisma
您应该阅读一些关于C字符串的内容(http://en.wikipedia.org/wiki/C_string)。一个c字符串,我是一个以null结尾的char数组。 –