| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:学函数调用遇到的问题.
只看楼主 加入收藏
静夜书生
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2007-3-18
收藏
 问题点数:0 回复次数:3 
学函数调用遇到的问题.
题目要求输入1990,然后输出1 9 9 0.
即在每个数字后面加一个空格.下面的是我编的,望有人指点一下.
#include<stdio.h>
int c[8];
main()
{
int *add(int c[]);
int i,*b,*f,a[4];
for (i=0;i<4;i++)
{
scanf ("%d",&a[i]);
}
b=add(a);
f=b;
for (;b<(f+8);b++)
printf("%d",*b);
}
int *add(int c[])
{
int *d,i;
for (i=0;i<8;i++)
{
c[2*i]=c[i];
c[2*i+1]=' ';
}
d=&c[0];
return d;
}
希望能在我写的基础上改,问题好象是在函数里的数组已经释放了.所以没结果
搜索更多相关主题的帖子: 函数 
2007-04-21 16:19
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 

我实在改不出来.
不过自己写了一个弥补自己的过失吧.呵呵.....
#define NULL 0
#include<stdio.h>
#include <string.h>
#include <malloc.h>

struct num
{
char ch;
struct num *next;
};
//初始化
struct num *initlist()
{
struct num *head;
head=(struct num *)malloc(sizeof(struct num));
head->next=NULL;
return head;
}
struct num *creat(struct num *head)//建表
{
struct num *p,*q;
char ch;
p=head;
puts("please input the original string:");
ch=getchar();
while(ch!='\n')
{
q=(struct num *)malloc(sizeof(struct num));
q->ch=ch;
q->next=NULL;
p->next=q;
p=q;
ch=getchar();
}
return head;
}
struct num *insert(struct num *head)//插入空格
{
struct num *p,*q;
q=head->next;
while (q!=NULL)
{

p=(struct num *)malloc(sizeof(struct num));
p->ch=' ';
p->next=q->next;
q->next=p;
q=q->next->next;
}
return head;
}
void display(struct num *head)//打印
{
struct num *p;
p=head->next;
while (p)
{
printf("%c",p->ch);
p=p->next;
}
}
int main(void)
{
struct num *head;
head=initlist();
head=creat(head);
head=insert(head);
display(head);
printf("\n");
return 0;
}


~~我的明天我知道~~
2007-04-21 17:33
静夜书生
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2007-3-18
收藏
得分:0 
唉,该怎么感谢你呢
2007-04-21 17:38
oclassic
Rank: 1
等 级:新手上路
帖 子:140
专家分:0
注 册:2007-4-18
收藏
得分:0 
以下是引用pinglideyu在2007-4-21 17:33:23的发言:

我实在改不出来.
不过自己写了一个弥补自己的过失吧.呵呵.....
#define NULL 0
#include<stdio.h>
#include <string.h>
#include <malloc.h>

struct num
{
char ch;
struct num *next;
};
//初始化
struct num *initlist()
{
struct num *head;
head=(struct num *)malloc(sizeof(struct num));
head->next=NULL;
return head;
}
struct num *creat(struct num *head)//建表
{
struct num *p,*q;
char ch;
p=head;
puts("please input the original string:");
ch=getchar();
while(ch!='\n')
{
q=(struct num *)malloc(sizeof(struct num));
q->ch=ch;
q->next=NULL;
p->next=q;
p=q;
ch=getchar();
}
return head;
}
struct num *insert(struct num *head)//插入空格
{
struct num *p,*q;
q=head->next;
while (q!=NULL)
{

p=(struct num *)malloc(sizeof(struct num));
p->ch=' ';
p->next=q->next;
q->next=p;
q=q->next->next;
}
return head;
}
void display(struct num *head)//打印
{
struct num *p;
p=head->next;
while (p)
{
printf("%c",p->ch);
p=p->next;
}
}
int main(void)
{
struct num *head;
head=initlist();
head=creat(head);
head=insert(head);
display(head);
printf("\n");
return 0;
}

原来是高手啊


编程群号码30772309群刚刚建立一个论坛http://tszbbs./?u=2 诚招斑猪哦
2007-04-21 17:54
快速回复:学函数调用遇到的问题.
数据加载中...
 
   



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

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