#include stdio.h

“專業(yè)、務(wù)實、高效、創(chuàng)新、把客戶的事當成自己的事”是我們每一個人一直以來堅持追求的企業(yè)文化。 創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、軟件開發(fā)、設(shè)計服務(wù)業(yè)務(wù)。我們始終堅持以客戶需求為導(dǎo)向,結(jié)合用戶體驗與視覺傳達,提供有針對性的項目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領(lǐng)市場!
#include string.h
int main()
{
int i = 0;
int len = 0;
char ch;
char buf[256] = {0};
char nor[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char enc[26] = {'s','u','w','y','a','c','e','g','i','k','m','o','q','r','t','v','x','z','b','d','f','h','j','l','n','p'};
printf("Encode or Decode: ");
scanf("%c",ch);
printf("please input your string: ");
fflush(stdin);
gets(buf);
len = strlen(buf);
switch (ch)
{
case 'e':
case 'E':
for (i=0;ilen;i++)
{
buf[i] = enc[buf[i] - 'a'];
}
break;
case 'd':
case 'D':
for (i=0;ilen;i++)
{
buf[i] = nor[i];
}
break;
default:
printf("wrong input!\n");
}
printf("%s\n",buf);
return 0;
}
同意樓上!
if (command == "encode") 出錯!
分析:
首先,輸出encode后,encode確實存入到數(shù)組command[6]中了。
但是,command是該數(shù)組的首地址,即變量command[0]的地址。它是個常數(shù)。
一個常數(shù)==字符串是永遠不成立的。即,command == "encode" 不成立。
我知道,你的意思是command所代表的數(shù)組里存放的字符串==“encode”,但是C語言不是這么規(guī)定的。所以,只能利用字符串比較函數(shù)strcmp(). PS:全稱string compare。
strcmp(字符串1,字符串2),如果兩個字符串相等,則其返回值為0.
所以,if語句改為:if (strcmp(command, "encode") == 0), 程序就能正常運行了。
另外,strcmp函數(shù)在頭文件string.h中,故要#include string.h
C語言出現(xiàn)expected identifier or '('是出現(xiàn)了編寫錯誤,Error Message:Compilation failed with errors:q2/frac.c:32:1: expected identifier or '('
在這段程序中:void fr_reduce(struct frac *a) {int g = gcd((*a).num, (*a).denom);(*a).num = ((*a).num / g);(*a).denom = ((*a).denom / g);if((*a).denom 0){(*a).denom = -(*a).denom;}}
問題出在:{int s;s=a+b;return(s);}前面缺了函數(shù)首部,應(yīng)為:int sum(int a,int b){int s;s=a+b;return(s);}
擴展資料:
C語言是一門通用計算機編程語言,廣泛應(yīng)用于底層開發(fā)。C語言的設(shè)計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產(chǎn)生少量的機器碼以及不需要任何運行環(huán)境支持便能運行的編程語言。
C語言一共只有32個關(guān)鍵字,9種控制語句,程序書寫形式自由,區(qū)分大小寫。把高級語言的基本結(jié)構(gòu)和語句與低級語言的實用性結(jié)合起來。C 語言可以像匯編語言一樣對位、字節(jié)和地址進行操作,而這三者是計算機最基本的工作單元。
盡管C語言提供了許多低級處理的功能,但仍然保持著良好跨平臺的特性,以一個標準規(guī)格寫出的C語言程序可在許多電腦平臺上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業(yè)平臺。
參考資料:百度百科-c語言
// Encode.cpp : 定義控制臺應(yīng)用程序的入口點。
//
#include "stdafx.h"
#define N 6
void show(int x[],int n);
void encode(int x[],int n,int y[]);
void swap(int *x,int *y);
int getNum(int x);
int _tmain(int argc, _TCHAR* argv[])
{
int x[]={13,25,135,246,1357,2468};
int y[6]={0};
encode(x,N,y);
show(x,N);
show(y,N);
getchar();
return 0;
}
void encode(int x[],int n,int y[])
{
for(int i=0;in;i++)
y[i]= getNum(x[i]);
}
int getNum(int x)
{
int len=0;
int t[]={1,2,3,4,5,6,7,8,9};
int m[9]={0};
int i=0,p=0;
int temp = x;
i=0;
while(temp!=0)
{
m[i]=temp%10;
i++;
len++;
temp=temp/10;
}
for(int i=0;ilen;i++)
{
m[i]=(m[i]+t[i])%10;
}
swap(m[0],m[len-1]);
int count = 1,sum = 0;
for(int i=0;ilen;i++)
{
m[i]=m[i]*count;
sum=sum+m[i];
count = count*10;
}
return sum;
}
void show(int x[],int n)
{
for(int i=0;in;i++)
printf("%d\t",x[i]);
printf("\n");
}
void swap(int *x,int *y)
{
int t=*x;
*x=*y;
*y=t;
}
當前文章:C語言encode函數(shù) c語言enable函數(shù)
分享鏈接:http://www.yijiale78.com/article44/ddgcihe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、App設(shè)計、網(wǎng)站維護、軟件開發(fā)、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容