C字符存诸操作



char OsdEndBuf[100][255];
char DisplayOsdBuf[100][255];
char Txt[50]="Txt", s1_text[50]="s1_text";
int Line=-1;

int
coyOsdbuf() //把文本中的内容复制到数组里
{
int i=-1;
char *osdfp;
char OsdBuf[255];
memset(OsdEndBuf,0,sizeof(OsdEndBuf));
if((osdfp=fopen(OSD_FILEF,"r"))==NULL)
{
printf("can not open file!\n");
return 0;
}
while(fgets(OsdBuf,155,osdfp))
{
i++;
strcpy(OsdEndBuf[i],OsdBuf);
}
}

char* delete_rdu(char *str) //去掉等号左边的字符
{
int i,j,k;
for(i=j=0;str[i]!='\0';i++)
{
if(str[i]=='=')
{
j=i+1;
}
}
for(k=0;str[j]!='\0';j++)
{
str[k++]=str[j];
}
str[k]='\0';
return str;
}

int displayOsd() //格式化文本里的字符去掉“=”号左边的字符。取出右边的字符
{
int i=0,j;
char rithfbuf[255];
coyOsdbuf();
memset(DisplayOsdBuf,0,sizeof(DisplayOsdBuf));

for(i=0;i<50;i++)
{
delete_rdu(OsdEndBuf[i+1]);
strcpy(DisplayOsdBuf[i],OsdEndBuf[i+1]);
printf("ssss %s\n",DisplayOsdBuf[i]);
}

}

int copyOsd(int i,char judgebuf[],char endbuf[],char_t *webvalue) //i为行数,judgebuf为指定要改的字符,endbuf从文本中读到的字符,webvalue为页面传的字符
{
char OsdMidBuf[255];
char judgendbuf[255]; //judgendbuf是把judgebuf改为与文件里对应的字符格式比如Txt2=
if(strstr(endbuf,T(judgebuf))!=NULL)
{
memset(OsdMidBuf,0,sizeof(OsdMidBuf));
strcpy(judgendbuf,judgebuf); //传来的judgebuf是常量,要把它放到judgendbuf中
strcat(judgendbuf,"="); //加“=”号
strcat(judgendbuf,webvalue); //与要改的字符合并 如Txt2=22
snprintf(OsdMidBuf, sizeof(OsdMidBuf), "%s\n",judgendbuf); //格式化加换行符
strcpy(OsdEndBuf[i],OsdMidBuf);
}
}

int copyChar(int i)
{
Txt[50]="Txt", s1_text[50];
if(1==i)
{
strcat(Txt,"2");
memset(s1_text,0,sizeof(s1_text));
snprintf(s1_text, sizeof(s1_text), "s2_%s\n","text");
}

}

if (0 == gstricmp(pszOperate, T("set")))
{
char_t *pszJudge = NULL;
pszJudge=websGetVar(wp, T("text_judge"), T(""));
printf("ttttt%s\n",pszJudge);

if (0 == gstricmp(pszJudge, T("1")))
{
char OsdBuf[255];
memset(OsdBuf,0,sizeof(OsdBuf));
int Line=-1,i;
pszTxt=websGetVar(wp, T("s1_text"), T(""));
pszSizet=websGetVar(wp, T("s1_text_size"), T(""));
pszOutline=websGetVar(wp, T("s1_text_outline"), T(""));
pszBold=websGetVar(wp, T("s1_text_bold"), T(""));
pszItalic=websGetVar(wp, T("s1_text_italic"), T(""));
pszColor=websGetVar(wp, T("s1_text_color"), T(""));
pszStartX=websGetVar(wp, T("s1_text_startx"), T(""));
pszStartY=websGetVar(wp, T("s1_text_starty"), T(""));
pszTimabl=websGetVar(wp, T("s1_time_enable"), T(""));
printf("No___1\n");


coyOsdbuf(); //先把文件复制到数组中
if((osdfp=fopen(OSD_FILEF,"r"))==NULL)
{
printf("can not open file!\n");
return 0;
}
while(fgets(OsdBuf,155,osdfp)) //从文件开始读存到OsdBuf中
{
Line++;
copyOsd(Line,"Txt1",OsdBuf,pszTxt);
copyOsd(Line,"Sizet1",OsdBuf,pszSizet);
copyOsd(Line,"Outline1",OsdBuf,pszOutline);
copyOsd(Line,"Bold1",OsdBuf,pszBold);
copyOsd(Line,"Italic1",OsdBuf,pszItalic);
copyOsd(Line,"Color1",OsdBuf,pszColor);
copyOsd(Line,"StartX1",OsdBuf,pszStartX);
copyOsd(Line,"StartY1",OsdBuf,pszStartY);
copyOsd(Line,"Timabl1",OsdBuf,pszTimabl);
}

fclose(osdfp);
//saveOsd();

if((osdfp=fopen(OSD_FILEF,"w"))==NULL)
{
printf("can not open file!\n");
return 0;
}
else
{
for(i=0;i<=Line;i++)
{
fputs(OsdEndBuf[i],osdfp);
}
fclose(osdfp);
}
printf("No___1");
}



static void formNetworkSet(webs_t wp, char_t *path, char_t *query)
{
char_t *szAddr, *szMask, *szGate;
szAddr = websGetVar(wp, T("Address"),T(""));
szMask = websGetVar(wp, T("Submask"),T(""));
szGate = websGetVar(wp, T("Gateway"),T(""));

FILE* fp=NULL;
int i,Lid = -1;
char szBuf[128];
char szTemp[128];
char szTmp[20][256];
memset(szTmp,0,sizeof(szTmp));
memset(szBuf,0,sizeof(szBuf));

if((fp=fopen(NETWORK_FILE, "r+"))==NULL)
{
printf( "setIP Can 't open file!\n");
return;
}
while(fgets(szBuf,256,fp))
{
Lid++;
if('#' != *szBuf)
{
if(strstr(szBuf,T("address")) != NULL) //从文本第一行开始匹配
{
memset(szTemp,0,sizeof(szTemp));
snprintf(szTemp, sizeof(szTemp), "\taddress %s\n",szAddr); //格式化字符串
strcpy(szTmp[Lid],szTemp); //复制
}else if(strstr(szBuf,T("netmask")) != NULL)
{
memset(szTemp,0,sizeof(szTemp));
snprintf(szTemp, sizeof(szTemp), "\tnetmask %s\n",szMask);
strcpy(szTmp[Lid],szTemp);
}else if(strstr(szBuf,T("gateway")) != NULL)
{
memset(szTemp,0,sizeof(szTemp));
snprintf(szTemp, sizeof(szTemp), "\tgateway %s\n",szGate);
strcpy(szTmp[Lid],szTemp);
}else
strcpy(szTmp[Lid],szBuf);
}else{
strcpy(szTmp[Lid],szBuf);
}
}
fclose(fp);
if((fp=fopen(NETWORK_FILE, "w"))==NULL)
{
printf( "writeIP Can 't open file!\n");
websRedirect(wp, T("network.asp"));
return;
}else{
for(i = 0;i <=Lid;i++)
fputs(szTmp[i],fp);
fclose(fp);
}
websRedirect(wp, T("network.asp"));
return;
}


原文地址:https://www.cnblogs.com/qingjoin/p/2271820.html