查找整数问题 [英] Finding the Integers Question

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

问题描述

您好,


我是C的新手所以请原谅我的无能。


如果给我一个文件" jfewuuj3uefi8jkw128jdmnsdf\ ;;''d1904"


我想将每个0-9整数的出现捕获到数组中。


所以在阵列中我会有{3,8,1,2,8,1,9,0,4}


我该怎么做呢? SCANF? fgets?


谢谢:)

Hello,

I''m very new to C so please forgive my ineptitude.

If I am given a file with "jfewuuj3uefi8jkw128jdmnsdf\s;''d1904"

I want to capture each occurence of an integer 0-9 into an array.

So in the array I would have {3,8,1,2,8,1,9,0,4}

How would I go about doing this? scanf? fgets?

Thank you :)

推荐答案

jobo写道:
jobo wrote:

你好,


我是C的新手所以请原谅我的无能。


如果给我一个带有jfewuuj3uefi8jkw128jdmnsdf \ s;''d1904"


的文件,我想将每个0-9整数的出现捕获到一个数组中。


所以在数组中我会有{3,8,1,2,8,1,9,0,4}


怎么样?我这样做了吗? SCANF?与fgets?
Hello,

I''m very new to C so please forgive my ineptitude.

If I am given a file with "jfewuuj3uefi8jkw128jdmnsdf\s;''d1904"

I want to capture each occurence of an integer 0-9 into an array.

So in the array I would have {3,8,1,2,8,1,9,0,4}

How would I go about doing this? scanf? fgets?



看看fgetc和isdigit。


-

Thomas M. Sommers - tm*@nj.net - AB2SB

Take a look at fgetc and isdigit.

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB


这里我的代码就是:

arr [i] = fgetc("%d");


我正在接受a从不兼容的指针传递''fgetc''的参数1

type"错误。


T.M. Sommers写道:
Here''s what I have in my code:
arr[i] = fgetc("%d ");

I''m gettting a "passing argument 1 of ''fgetc'' from incompatible pointer
type" error.

T.M. Sommers wrote:

jobo写道:
jobo wrote:

你好,


我是C的新手所以请原谅我的无能。


如果给我一个文件jfewuuj3uefi8jkw128jdmnsdf \ s;''d1904"


我想将每个0-9整数的出现捕获到一个数组中。


所以在数组中我会得到{3,8,1, 2,8,1,9,0,4}


我该怎么做呢? SCANF?与fgets?
Hello,

I''m very new to C so please forgive my ineptitude.

If I am given a file with "jfewuuj3uefi8jkw128jdmnsdf\s;''d1904"

I want to capture each occurence of an integer 0-9 into an array.

So in the array I would have {3,8,1,2,8,1,9,0,4}

How would I go about doing this? scanf? fgets?



看看fgetc和isdigit。


-

Thomas M. Sommers - tm*@nj.net - AB2SB


Take a look at fgetc and isdigit.

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB


jobo写道:
jobo wrote:

TM Sommers写道:
T.M. Sommers wrote:

>> jobo写道:
>>jobo wrote:

>>> I'对C来说很新,所以请原谅我的无能。

如果给我一个带有jfewuuj3uefi8jkw128jdmnsdf \;的文件''d1904"

我想抓住每个出现0到整数的整数。

所以在数组中我会有{3,8,1,2,8,1,9,0,4}

我该怎么做呢? SCANF?与fgets?
>>>I''m very new to C so please forgive my ineptitude.

If I am given a file with "jfewuuj3uefi8jkw128jdmnsdf\s;''d1904"

I want to capture each occurence of an integer 0-9 into an array.

So in the array I would have {3,8,1,2,8,1,9,0,4}

How would I go about doing this? scanf? fgets?


看看fgetc和isdigit。


Take a look at fgetc and isdigit.



这是我在代码中的内容:

arr [i] = fgetc("%d");


我从不兼容的指针中获取fgetc的传递参数1

type"错误。


Here''s what I have in my code:
arr[i] = fgetc("%d ");

I''m gettting a "passing argument 1 of ''fgetc'' from incompatible pointer
type" error.



阅读fgetc的手册页。它需要一个FILE *作为参数,

并返回一个int。你想要这样的东西:


int ch;

while((ch = fgetc(file_pointer))!= EOF){

if(isdigit(ch)){

/ *你的数组中的东西ch * /

}

}


假设file_pointer是一个FILE *并且已经成功打开了用于阅读的
,并且相应的头文件已经是

#included。


-

Thomas M. Sommers - tm*@nj.net - AB2SB

Read the man page for fgetc. It takes a FILE * as an argument,
and returns an int. You want something like this:

int ch;
while ( (ch = fgetc(file_pointer)) != EOF ) {
if ( isdigit(ch) ) {
/* stuff ch in your array */
}
}

Assuming file_pointer is a FILE * and has been successfully
opened for reading, and the appropriate header files have been
#included.

--
Thomas M. Sommers -- tm*@nj.net -- AB2SB


这篇关于查找整数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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