代码问题在哪里? [英] Where the code trouble is?

查看:92
本文介绍了代码问题在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候:


代码问题在哪里?

#include< windows.h>

#include< ; stdio.h>

#include< stdlib.h>

#include< string.h>


int main(){


char * name;

char * title;

printf("输入你的名字:" );

scanf("%s",name);

title = strcat(name,the great);

printf(你好,%s \ n,标题);

返回(0);

}


--------------------------------------------


谢谢

可以和你们一起好好

Regards:

Where the code trouble is?
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){

char *name;
char *title;
printf( "Enter your name:");
scanf( "%s", name );
title = strcat(name,"the Great");
printf( "Hello, %s\n", title );
return(0);
}

--------------------------------------------

thank you
may goodness be with you all

推荐答案



mikelinyoho写道:

mikelinyoho wrote:
问候:

代码问题在哪里?

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

int main(){
char * name;
char * title;
printf("输入你的名字:");
scanf("%s",name);
Name是没有内存关联的指针.Scanf不分配

内存。

将char * name更改为数组。使用fgets而不是scanf来避免

溢出问题。 title = strcat(name,the Great);
printf(Hello,%s \ n,title);
return(0);
}

--------------------------------------------

谢谢
好的和你在一起
Regards:

Where the code trouble is?
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){

char *name;
char *title;
printf( "Enter your name:");
scanf( "%s", name ); Name is a pointer with no memory associated.Scanf dont allocate
memory.
Change char * name to an array.Use fgets instead of scanf to avoid
overflow issues. title = strcat(name,"the Great");
printf( "Hello, %s\n", title );
return(0);
}

--------------------------------------------

thank you
may goodness be with you all






你得到编译错误还是什么?

你能更具体一点吗?


Alex。

Do you get compiler errors or what?
Can you be more specific?

Alex.



mikelinyoho写道:

mikelinyoho wrote:
问候:

代码问题在哪里?

#include< windows.h>


非标准标题

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


你真的需要这个吗?

#include< string.h>


#define MAXMUNCH。 .. / *一些足够大的尺寸* /

int main(){


int main(void){

稍微好一点。
char * name;
char * title;
printf("输入你的名字:");
scanf(" ;%s",name);


没有分配足够的(任何)内存 - 所以你要这么多了b $ b就死了。


Do name = malloc(sizeof * name * MAXMUNCH); title = strcat(name,the great);


...并加重侮辱伤害。

printf(你好,%s \ n,标题);
return(0);
}
Regards:

Where the code trouble is?
#include <windows.h>
non standard header
#include <stdio.h>
#include <stdlib.h>
Do you really need this?
#include <string.h>

#define MAXMUNCH ... /* some size big enough for you */
int main(){
int main(void){

is a tad bit better.
char *name;
char *title;
printf( "Enter your name:");
scanf( "%s", name );
Not allocated enough (any) memory -- so you''re
dead hereon.

Do name = malloc( sizeof *name * MAXMUNCH ); title = strcat(name,"the Great");
... and to add insult to injury.
printf( "Hello, %s\n", title );
return(0);
}






这篇关于代码问题在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆