64,691
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <assert.h>
#include<string.h>
// 全局变量
#define M 10
int j; //指向编码后序列的数组下标
int i; //输入码字的数组下标
int length; //求值输入数组的长度
int Manchester(char str0[]) //曼彻斯特编码
{
char Manchester[2*M];
memset(Manchester,0,2*M);
Manchester[0]='0';
Manchester[1]='1';
j=2;
// extern length;
for(i=0;i<length;i++)
{
// 循环入口数据
printf("current character is: %c ",str0[i]);
// 循环处理,0 ->01 1 ->10
if(str0[i]=='0') {Manchester[j++]='0';Manchester[j++]='1';}
else if(str0[i]=='1') {Manchester[j++]='1';Manchester[j++]='0';}
else {printf("input error,exit........ "); return 1;} // 输入出错
// 循环处理后数据
printf("-----");
printf("after process: %c%c ",Manchester[j-2],Manchester[j-1]);
}
// 结果字符串加上终结符
Manchester[j]=0;
// 输出结果
printf("------------------------------------------- ");
printf("Manchester coding is :%s ",Manchester);
return 0;
}