| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:找个大神 帮忙看看
取消只看楼主 加入收藏
wsws23
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:105
专家分:107
注 册:2012-3-13
结帖率:81.82%
收藏
已结贴  问题点数:20 回复次数:2 
找个大神 帮忙看看
#incldue
using namespace std;
struct teacher{
char* name;
char* fangxiang;
int cs;
};
void output(struct teacher * th)
{
    cout<name<<":"<fangxiang<cs<<ENDL;
}
int main()
{
    int n,i;
struct teacher * th;
cout<<"please input the number:"<<ENDL;
cin>>n;
th=new struct teacher[n];
if(th==NULL)
{
    cout<<"memory creat false!!"<<ENDL;
}
else
{
    (th+i)->name=new char[n];
    (th+i)->fangxiang=new char[n];
    if((th+i)->name==NULL&&(th+i)->fangxiang==NULL)
{
    cout<<"memory creat false!"<<ENDL;
}
}
for(i=0;i<n;i++)
<N;I++)
{
    cout<<"please input the data"<<ENDL;
    cin>>(th+i)->name;
    cin>>(th+i)->fangxiang;
    cin>>(th+i)->cs;
}
for(i=0;i<n;i++)
<N;I++)
{
    output(th);
}
for(i=0;i<n;i++)
{
    delete[] (th+i)->fangxiang;
    (th+i)->fangxiang=NULL;
    delete[] (th+i)->name;
    (th+i)->name=NULL;   
}
delete[] th;
th=NULL;
return 0;
}
编译没错误  运行后出现内存问题 不知道怎么解决 求大神 指点;
搜索更多相关主题的帖子: please memory teacher false 
2013-03-04 22:38
wsws23
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:105
专家分:107
注 册:2012-3-13
收藏
得分:0 
上一个程序 写的时候 有错误 从新写了一个:
#include<iostream>
using namespace std;
struct teacher{
char* name;
char* fangxiang;
int cs;
};
void output(struct teacher * th)
{
    cout<<th->name<<":"<<th->fangxiang<<th->cs<<endl;}
int main()
{
    int n,i;
struct teacher * th;
cout<<"please input the number:";
cin>>n;
th=new struct teacher[n];
if(th==NULL)
{
    cout<<"memory creat false!!"<<endl;}
else
{
    (th+i)->name=new char[n];
    (th+i)->fangxiang=new char[n];
    if((th+i)->name==NULL&&(th+i)->fangxiang==NULL)
{
    cout<<"memory creat false!"<<endl;}
}
for(i=0;i<n;i++)
{
    cout<<"please input the data"<<endl;
    cin>>(th+i)->name;
    cin>>(th+i)->fangxiang;
    cin>>(th+i)->cs;
}
for(i=0;i<n;i++)
{
    output(th);
}
for(i=0;i<n;i++)
{
    delete[] (th+i)->fangxiang;
    (th+i)->fangxiang=NULL;
    delete[] (th+i)->name;
    (th+i)->name=NULL;   
}
delete[] th;
th=NULL;
return 0;
}
2013-03-04 22:46
wsws23
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:105
专家分:107
注 册:2012-3-13
收藏
得分:0 
回复 3楼 邓士林
非常感谢 我也知道是内存的非配问题 只是不知道在哪  
内存不够 那不太可能吧
2013-03-04 23:31
快速回复:找个大神 帮忙看看
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012080 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved