我只是在学习C,并且想知道我应该在我的主要方法中使用哪一个.有什么区别吗?
编辑:那么哪一个更常用?
使用以下代码:
char *name = malloc(sizeof(char) + 256);
printf("What is your name? ");
scanf("%s", name);
printf("Hello %s. Nice to meet you.\n", name);
Run Code Online (Sandbox Code Playgroud)
用户可以输入他们的名字,但是当他们输入一个像空格一样的名字时Lucas Aardvark
,scanf()
只需切断后面的所有内容Lucas
.如何设置scanf()
允许空格
如果我malloc
在我的代码中使用:
int *x = malloc(sizeof(int));
Run Code Online (Sandbox Code Playgroud)
我收到以下警告gcc
:
new.c:7: warning: implicit declaration of function ‘malloc’
new.c:7: warning: incompatible implicit declaration of built-in function ‘malloc’
Run Code Online (Sandbox Code Playgroud) Parse()和TryParse()有什么区别?
int number = int.Parse(textBoxNumber.Text);
// The Try-Parse Method
int.TryParse(textBoxNumber.Text, out number);
Run Code Online (Sandbox Code Playgroud)
是否有某种形式的错误检查,如Try-Catch Block?
编辑:我添加了示例的源代码.
我遇到了这个例子:
char source[MAX] = "123456789";
char source1[MAX] = "123456789";
char destination[MAX] = "abcdefg";
char destination1[MAX] = "abcdefg";
char *return_string;
int index = 5;
/* This is how strcpy works */
printf("destination is originally = '%s'\n", destination);
return_string = strcpy(destination, source);
printf("after strcpy, dest becomes '%s'\n\n", destination);
/* This is how strncpy works */
printf( "destination1 is originally = '%s'\n", destination1 );
return_string = strncpy( destination1, source1, index );
printf( "After strncpy, destination1 becomes '%s'\n", destination1 );
Run Code Online (Sandbox Code Playgroud)
哪个产生了这个输出: …
我一直想制作RSS阅读器一段时间(只是为了好玩),但我对从哪里开始没有任何想法.我对RSS一无所知.有没有关于RSS的好教程以及如何在应用程序中实现它(不是关于如何制作RSS阅读器的教程,这太简单了).
我一直在看WPF,但我从来没有真正参与其中(除了15分钟,这促成了这个问题).我查看了这篇文章,但它真的是关于WPF的"Flash".那么Windows窗体应用程序和WPF应用程序之间有什么区别?