请问如何改写这个函数,返回一个整型数组.
1.我先介绍我这个函数功能:
把输入的字符串如"22222 3333 333 "
22222 3333 33三个数字存入一个整型数组
函数要求写成
int * GET(char *s)
的形式
指针无法传递
在主函数调用的时候如何帮函数局部的变量还存在?
问过一个高手,说用指针的指针可以解决,不过没有给出具体的实现,请CSDN的大虾帮忙解决
/////////////////////
以下程序是我想的笨办法,供修改使用
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
static int num[100];
static char temp[4];
int GET(char *s)//请教如何把这个函数改成int* GET(char *s)就是把字符串里的数字存入这个数组并且数组不被销毁
{
int len=strlen(s);
int count=0;
int count1=0;
for(int i=0;i<len;i++)
{
temp[count1]=s[i];
count1++;
if(isspace(s[i]))
{
//cout<<"wwww"<<temp<<endl;;
num[count]=atoi(temp);
count1=0;
count++;
}
}
return count;//数组元素个数
}
void main()
{
char *ss="21 321 33213 ";
int count=GET(ss);
for(int i=0;i<count;i++)
cout<<num[i]<<endl;
}
问题2.
请问C语言的为何char数组可以测其长度?
而int 数组为何没有提供这个方法?