1.1.2 参数C 库函数 void *memcpy(void *str1, const void *str2, size_t n) 从存储区 str2 复制 n 个字节到存储区 str1。
- str1 – 指向用于存储复制内容的目标数组,类型强制转换为 void* 指针。
- str2 – 指向要复制的数据源,类型强制转换为 void* 指针。
- n – 要被复制的字节数。
Status convert(int array[3][3])
{
int temp[3][3];
for (char i = 0; i < 3; i++)
{
for (char j = 0; j < 3; j++)
{
temp[j][i] = array[i][j];
}
}
//因为array和temp的空间是相同的所以用memcpy函数直接对它进行array=temp
memcpy(array, temp, sizeof(int) * 3 * 3);
return SUCCESS;//SUCCESS=1
}
所以可以看到memcpy可以把相同空间大小的两个东西进行复制
1.2.2 数据结构——泛型输出2. strcmp 比较 2.1 函数介绍 2.1.1 描述
2.1.2 参数C 库函数 int strcmp(const char *str1, const char *str2) 把 str1 所指向的字符串和 str2 所指向的字符串进行比较。
- str1 – 要进行比较的第一个字符串。
- str2 – 要进行比较的第二个字符串。
- 如果返回值小于 0,则表示 str1 小于 str2。
- 如果返回值大于 0,则表示 str1 大于 str2。
- 如果返回值等于 0,则表示 str1 等于 str2。
- 比较规则:两个字符串自左向右逐个字符相比(按 ASCII 值大小相比较),直到出现不同的字符或遇 为止。
如:
1."A"<"B" 2."A"<"AB" 3."Apple"<"Banana" 4."A"<"a" 5."compare"<"computer"
- 特别注意:strcmp(const char *s1,const char * s2) 这里面只能比较字符串,即可用于比较两个字符串常量,或比较数组和字符串常量,不能比较数字等其他形式的参数。
if(strcmp(userpass,temp)==0)2.2.2 对字符串进行排序
Status SortStr(char **str,int n)
{
char* temp = NULL;
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < 10; j++)
{
if (strcmp(str[i],str[j])>0)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
return SUCCESS;
}



