69,336
社区成员
发帖
与我相关
我的任务
分享
errno_t strcpy_s(
char *strDestination,
size_t numberOfElements,
const char *strSource
);
https://msdn.microsoft.com/en-us/library/td1esda9(VS.80).aspx
你的写的参数顺序是linux下的安全型字符串拷贝函数strncpy的顺序
char *strncpy(char *dest, const char *src, size_t n);
#include<stdio.h>
#include<string.h>
void swap(char*, char*);
int main(void)
{
char str1[40], str2[40], str3[40];
printf("input three line:\n");
gets_s(str1, 40);
gets_s(str2, 40);
gets_s(str3, 40);
if (strcmp(str1, str2) > 0)
swap(str1, str2);
if (strcmp(str1, str3) > 0)
swap(str1, str3);
if (strcmp(str2, str3) > 0)
swap(str2, str3);
printf("Now,the order is:\n");
printf("%s\n%s\n%s\n", str1, str2, str3);
}
void swap(char *p1, char *p2)
{
char p[40];
strcpy_s(p, 40, p1);
strcpy_s(p, 40, p2);
strcpy_s(p2, 40, p);
}
#include<stdio.h>
#include<string.h>
void main()
{
void swap(char*, char*);
char str1[40], str2[40], str3[40];
printf("input three line:\n");
gets(str1);
gets(str2);
gets(str3);
if (strcmp(str1, str2) > 0)
swap(str1, str2);
if (strcmp(str1, str3) > 0)
swap(str1, str3);
if (strcmp(str2, str3) > 0)
swap(str2, str3);
printf("Now,the order is:\n");
printf("%s\n%s\n%s\n", str1, str2, str3);
}
void swap(char *p1, char *p2)
{
char p[40];
strcpy(p, p1);
strcpy(p1, p2);
strcpy(p2, p);
}
原代码不设参数及参数范围情况下,在同学电脑xs2012环境下编译运行通过~
我的环境是vs2013,给跪了。