永发信息网

从键盘输入一个字符串,存入一个数组中,求输入的字符串的长度.

答案:3  悬赏:30  手机版
解决时间 2021-02-18 09:33
  • 提问者网友:孤山下
  • 2021-02-18 02:18
#include
#include
main()
{
int func(int string[]) ;
int n;
printf("Input a string:");
gets(string);
n=strlen(string);
return(string)
printf("n=%d",n);
}
最佳答案
  • 五星知识达人网友:冷風如刀
  • 2021-02-18 03:42
你的 int func(int string[]是函数的声明,不是字符串的声明;还有 不能声明字符串为string,因为string是c语言已经定义的关键字,其实就是头文件了,可以这样写:
#include
#include
int main()
{
char str[100];
int n;
gets(str);
n=strlen(str);
printf("n==%d\n",n);
}
全部回答
  • 1楼网友:低血压的长颈鹿
  • 2021-02-18 06:19
int func(int string[])是在干啥……把这一行改成 char string[100]试试
  • 2楼网友:底特律间谍
  • 2021-02-18 04:56
给你修改了下,可以试试: import java.io.*; import java.util.*; class tosort { private int a[] = new int[10]; private int count = 0; private scanner scn; int[] tovalue() { system.out.println("请输入数字,按回车键换行,最多输入10个数字,输入over直接结束:"); scn = new scanner(system.in); while (scn.hasnext()) { string receive = scn.next(); if ("".equals(receive)) continue; if ("over".equals(receive)) { system.out.println("输入完成!"); break; } if (count < 10) { try { a[count] = integer.parseint(receive); count++; } catch (numberformatexception e) { system.out.println("输入的非数字都被视为无效!"); continue; } } else { system.out.println("已经到最大值,不能在输入,此次输入无效!"); break; } } return a; } void use() throws ioexception { tovalue(); int[] newarray = new int[count]; system.out.println("您输入的数字有:"); for (int i = 0; i < count; i++) { newarray[i] = a[i]; if (i == count-1) system.out.println(a[i]); else system.out.print(a[i] + ","); } arrays.sort(newarray); system.out.println("排序结果如下:"); for (int i = 0; i < newarray.length; i++) { if (i == count-1) system.out.print(newarray[i]); else system.out.print(newarray[i] + ","); } } public static void main(string args[]) throws ioexception { tosort ts = new tosort(); ts.use(); } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯