首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

程序有警告,该如何处理

2013-03-26 
程序有警告#include stdio.hchar strtobit(char str[]) {char result0,i0for(i0str[i]!\0++i)

程序有警告

#include <stdio.h>


char strtobit(char str[]) {
    char result=0,i=0;

    for(i=0;str[i]!='\0';++i) {
        result = (result<<1) + str[i] - '0';
    }
    return result;
}



int main() {
    char source[]="ddssssasdfasdfasdfaqwfasdfawefasdfasdfawedasdfaw";

    int i=1,j=0;
    char tmp1[9];
    for(i=1;source[i]!='\0';++i)  {
        tmp1[j]=source[i];
        j++;
        if(i%8==0) {
        tmp1[j] = '\0';
        printf('%s', tmp1);
            printf('%c', strtobit(tmp1));
            j=0;
        }
    }
    getch();
}

就这么个程序,小弟是个初学者,编译器老说我的tmp1是个常量,运行的时候没有任何打印
[解决办法]

#include <stdio.h>
#include <conio.h> 

char strtobit(char str[]) {
    char result=0,i=0;

    for(i=0;str[i]!='\0';++i) 
{
        result = (result<<1) + str[i] - '0';
    }
    return result;
}



int main() {
    char source[]="ddssssasdfasdfasdfaqwfasdfawefasdfasdfawedasdfaw";

    int i=1,j=0;
    char tmp1[9];
    for(i=1;source[i]!='\0';++i)  
{
        tmp1[j]=source[i];
        j++;
        if(i%8==0) 
{
tmp1[j] = '\0';
printf("%s\n",tmp1);//应该是双引号
            printf("%c\n", strtobit(tmp1));//应该是双引号
            j=0;
        }
    }
    getch();//头文件应该包含#include <conio.h> 
}

热点排行