| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1847 人关注过本帖
标题:求助!請C語言高手幫我看看這個錯在哪裡~
只看楼主 加入收藏
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
不一定阿,但是说真的,一个程序员必须有耐性,不能浮躁,否则会很吃亏的……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-09 10:46
rdt151
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-9
收藏
得分:0 
#include<stdio.h>
#include<math.h>

void main()
{
long int number;
int indiv,ten,hund,thou,t_th; /*分别代表个位、十位、百位、千位、万位*/
printf("place input a whole number(0~99999):\n");
scanf("%ld",&number);

if(number<0||number>99999) printf("The date is error\n");
else if(number>9999)printf("place=5");
else if(number>999)printf("place=4");
else if(number>99)printf("place=3");
else if(number>9)printf("place=2");
else printf("place=1");
printf("each number is:");
t_th=number/10000;
thou=(int)(number-t_th*10000)/1000;
hund=(int)(number-t_th*10000-thou*1000)/100;
ten=(int)(number-t_th*10000-thou*1000-hund*100)/10;
indiv=(int)(number-t_th*10000-thou*1000-hund*100-ten*10);

{
if(number>9999)
{printf("%d,%d,%d,%d,%d",t_th,thou,hund,ten,indiv);
printf("\nThe reverse number is:");
printf("%d%d%d%d%d\n",indiv,ten,hund,thou,t_th);
}
else if(number>999)
{printf("%d,%d,%d,%d",thou,hund,ten,indiv);
printf("\nThe reverse number is:");
printf("%d%d%d%d\n",indiv,ten,hund,thou);
}
else if(number>99)
{printf("%d,%d,%d",hund,ten,indiv);
printf("\nThe reverse number is:");
printf("%d%d%d\n",indiv,ten,hund);
}
else if(number>9)
{printf("%d,%d",ten,indiv);
printf("\nThe reverse number is:");
printf("%d%d\n",indiv,ten);
}
else
{printf("%d",indiv);
printf("\nThe reverse number is:");
printf("%d\n",indiv);
}
}
getch();
}
2008-10-09 14:21
allback
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-9-16
收藏
得分:0 
我觉得这里也有问题
如果输入一个10000,它>9999,>999,>99,>9,10000这些都满足啊,后面的那段if的逻辑是不是就混乱了???
2008-10-09 15:50
x313867388
Rank: 1
来 自:中国
等 级:新手上路
帖 子:20
专家分:0
注 册:2008-10-4
收藏
得分:0 
我倒`我愣是看不明白,大哥,我马上就考试了,这次真倒了。`
2008-10-09 17:00
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <string.h>

int main(void)
{
    char num[101], *pt;
    while (scanf(" %100[0-9]",num) == 1)
    {
        printf("place = %d\n", strlen(num));
        for (pt = num; *pt; pt++)
            printf("%c%c", *pt, pt[1] ? ',' : '\n');
        while (--pt >= num)
            printf("%c%c", *pt, pt != num ? ',' : '\n'); 
    }
    return 0;
}


这代码真的需要这么长么?

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-09 20:50
紫色杀戮
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-10-10
收藏
得分:0 
原始文件内容:
000mA 253mA 253mA 129mA 254mA 254mA 253mA 253mA 129mA 253mA 129mA 129mA
135mA 225mA 225mA 193mA 128mA 135mA 225mA 225mA 193mA 225mA 193mA 193mA
000mA 000mA 000mA 000mA 000mA 000mA 000mA ...
问题:是把上面的mA变成空格,然后存到一个新的文件里面
目前的的进展:
#include  "stdio.h"
#include  "stdlib.h"
main()
{
 FILE *fp1,*fp2;
 int b[5];
 int a[71];
 char i,j;
 if((fp1=fopen("d:\\mcutest\\tc\\fu\\file3.txt","r"))==NULL)
   {
    cputs("can not open the file\n");
    fclose(fp1);
   }
  fp2=fopen("d:\\mcutest\\tc\\fu\\file4.txt","w");
  while(fgets(i,71,fp1)!=NULL)
  switch(isalpha(i))
    {
     case '0':printf("%c is not a char\n",i);

          break;
     default:printf("%c ifs a char\n",j);

         break;
    }
 fclose(fp2);
 return;
}

还达不到我要的结果,希望大家帮忙。先谢谢了。一定要用C语言编程哦
2008-10-10 14:37
xlaozhu2009
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-10
收藏
得分:0 
dddddddddddd
2008-10-10 21:39
xfcy
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-9-15
收藏
得分:0 
我也写了个
#include "stdio.h"
#define N 5
int main()
{
  int x,a[N],i=0,j;
    printf("input the num:");
    scanf("%ld",&x);
    while(x)
    {
        a[i]=x%10;
        x=(x-a[i])/10;
        i++;
    }
    for(i=N-1;i>=0;i--)
    if(a[i]!=0)
    {printf("%d\n",i+1);
        for(j=i;j>=0;j--)
        printf("%3d",a[j]);
        printf("\n");
        for(j=0;j<=i;j++)
        printf("%d",a[j]);
        break;
    }
    else{;}
        return 0;
}
2008-10-10 23:31
flydream0
Rank: 1
等 级:新手上路
帖 子:20
专家分:7
注 册:2008-10-10
收藏
得分:0 
[bo][un]紫色杀戮[/un] 在 2008-10-10 14:37 的发言:[/bo]

原始文件内容:
000mA 253mA 253mA 129mA 254mA 254mA 253mA 253mA 129mA 253mA 129mA 129mA
135mA 225mA 225mA 193mA 128mA 135mA 225mA 225mA 193mA 225mA 193mA 193mA
000mA 000mA 000mA 000mA 000mA 000mA 00 ...

试下这个:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define Dmalloc    malloc
#define Drealloc realloc
#define Dfree free
#define FS_Open(name, oflag)             fopen(name, oflag)
#define FS_Close(fp)                     fclose(fp)
#define FS_Seek(fp, offset, whence)     fseek(fp, offset, whence)
#define FS_Tell(fp)                     ftell(fp)
#define FS_Read(ptr, size, nitem, fp)     fread(ptr, size, nitem, fp)
#define FS_Write(ptr, size, nitem, fp)     fwrite(ptr, size, nitem, fp)


void main(void)
{
    FILE *stream,*stream2;
    char *sfilepath="test.txt";
    char *dfilepath="test1.txt";
    char *chrTarget,*chrSource;
    char *chrbegin;
    int inifilesize,intnumread,intpos,intsum,intTemp1,intTemp2;

    
    if( (stream = FS_Open( sfilepath, "r+b" )) == NULL )
    {
      printf( "The file 'test.txt' was not opened or not exist!\n" );
    }
   else
   {
       if (FS_Seek(stream, 0, SEEK_END)!= 0) //move the file point the end of file
        {
            printf( "move the file point to the end of file failed!\n" );
        }
        inifilesize=FS_Tell(stream);//get current file size
        if (FS_Seek(stream, 0, SEEK_SET)!= 0) //move the file point to the begin of file again
        {
            printf( "move the file point to the begin of file failed!\n" );
        }
        chrSource=(char*)Dmalloc(inifilesize);
        if( NULL==chrSource )
        {
            printf( "Insufficient memory available\n" );
        }
        intnumread = FS_Read( chrSource, sizeof( char ), inifilesize, stream );//get file stream
        chrbegin=chrSource;
        
        chrTarget=(char*)Dmalloc(inifilesize);
        if( NULL==chrTarget )
        {
            printf( "Insufficient memory available\n" );
        }
        printf("******************************************************************************\n");
        printf("The contents of test.txt is showed as below:\n%s\n", chrSource );

        intsum=0;
        for (intTemp1=0;intTemp1<inifilesize;intTemp1++)
        {
            intpos=strcspn(chrbegin,"mA");
            for (intTemp2=0;intTemp2<intpos;intTemp2++)
            {
                if (chrbegin-chrSource>=inifilesize)
                    break;
                *(chrTarget+intsum)=*chrbegin;
                chrbegin++;
                
                intsum++;
            }
            if (chrbegin-chrSource>=inifilesize)
                break;
            else
                chrbegin+=strlen("mA");
        }
        *(chrTarget+intsum)=0;
        printf("%s ",chrTarget);

        if( (stream2 = FS_Open( dfilepath, "a" )) == NULL )
        {
            printf( "The file 'test.txt' was not opened or not exist!\n" );
        }
        intnumread = FS_Write( chrTarget, sizeof( char ), strlen(chrTarget), stream2 );
        printf("the number of characters had been writeen is:%d",intnumread);
   }
   Dfree(chrSource);
   Dfree(chrTarget);
   FS_Close(stream);
   FS_Close(stream2);
}

[[it] 本帖最后由 flydream0 于 2008-10-11 04:45 编辑 [/it]]
2008-10-11 04:35
flydream0
Rank: 1
等 级:新手上路
帖 子:20
专家分:7
注 册:2008-10-10
收藏
得分:0 
源文件路径和目标路径自已在定义中改吧。
2008-10-11 04:48
快速回复:求助!請C語言高手幫我看看這個錯在哪裡~
数据加载中...
 
   



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

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