易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : c++

C/C++字符串匹配和替换

题目:输入三个字符串a,b和c,将a中b的第一次出现替换为c。
代码:
#include <iostream.h>
#include <string.h>
/*字符串替换,第一个参数为原串,第二个参数为要匹配的子串
第三个参数为要替换的第一个子串中包含第二个子串的部分*/
char *strReplace(char *str1,char *str2,char *str3);
void main()
{
       char str1[255]={'\0'},str2[255]={'\0'},str3[255]={'\0'};
       cin>>str1;
       cin>>str2;
       cin>>str3;
       strcpy(str3,strReplace(str1,str2,str3));
       cout<<str3<<endl;
}
/*字符串查找匹配函数,查找第二个字符串在第一个字符串中的位置*/
//涛涛认为自己写的这个字符串匹配函数还是很有使用价值的,正在学习
int strSearch(char *str1,char *str2)
{
       int at,flag=1;
       if (strlen(str2) > st ......

C/C++字符串匹配和替换

题目:输入三个字符串a,b和c,将a中b的第一次出现替换为c。
代码:
#include <iostream.h>
#include <string.h>
/*字符串替换,第一个参数为原串,第二个参数为要匹配的子串
第三个参数为要替换的第一个子串中包含第二个子串的部分*/
char *strReplace(char *str1,char *str2,char *str3);
void main()
{
       char str1[255]={'\0'},str2[255]={'\0'},str3[255]={'\0'};
       cin>>str1;
       cin>>str2;
       cin>>str3;
       strcpy(str3,strReplace(str1,str2,str3));
       cout<<str3<<endl;
}
/*字符串查找匹配函数,查找第二个字符串在第一个字符串中的位置*/
//涛涛认为自己写的这个字符串匹配函数还是很有使用价值的,正在学习
int strSearch(char *str1,char *str2)
{
       int at,flag=1;
       if (strlen(str2) > st ......

C/C++ style

 #include <stdio.h>
int main()
{
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p + 1 );
str[2] = p[1] + 3;
str[3] = p[0] + ( str[2] - str[1] );
printf ( "%s\n", str[0] );
printf ( "%s\n", str[1] );
printf ( "%s\n", str[2] );
printf ( "%s\n", str[3] );
return 0;
}//这种风格是ansi
#include <stdio.h>
int main() {
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p + 1 );
str[2] = p[1] + 3;
str[3] = p[0] + ( str[2] - str[1] );
printf ( "%s\n", str[0] );
printf ( "%s\n", str[1] );
printf ( "%s\n", str[2] );
printf ( "%s\n", str[3] );
return 0;
}//这种风格叫K&R
#include <stdio.h>
int main()
{
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p ......

C/C++ style

 #include <stdio.h>
int main()
{
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p + 1 );
str[2] = p[1] + 3;
str[3] = p[0] + ( str[2] - str[1] );
printf ( "%s\n", str[0] );
printf ( "%s\n", str[1] );
printf ( "%s\n", str[2] );
printf ( "%s\n", str[3] );
return 0;
}//这种风格是ansi
#include <stdio.h>
int main() {
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p + 1 );
str[2] = p[1] + 3;
str[3] = p[0] + ( str[2] - str[1] );
printf ( "%s\n", str[0] );
printf ( "%s\n", str[1] );
printf ( "%s\n", str[2] );
printf ( "%s\n", str[3] );
return 0;
}//这种风格叫K&R
#include <stdio.h>
int main()
{
char *str[] = {"welcome", "to", "fortemedia", "nanjing"};
char **p = str + 1;
str[0] = ( *p++ ) + 2;
str[1] = * ( p ......

C/C++——小编谈C语言函数那些事(22)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.    setmem函数
setmem函数的功能是存值到存储区,其用法为:void setmem(void *addr, int len, char value);程序实例如下:
#include <stdio.h>
#include <alloc.h>
#include <mem.h>
int main(void)
{
   char *dest;
   dest = calloc(21, sizeof(char));
   setmem(dest, 20, 'c');
   printf("%s\n", dest);
   return 0;
}
 2.   setmode函数
setmode函数的功能是设置打开文件方式,其用法为int setmode(int handle, unsigned mode);程序实例代码如下:
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
   int result;
   result = setmode(fileno(stdprn), O_TEXT);
   if (result == -1)
      perror("Mode not available\n");
   else
     ......

C/C++——小编谈C语言函数那些事(22)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.    setmem函数
setmem函数的功能是存值到存储区,其用法为:void setmem(void *addr, int len, char value);程序实例如下:
#include <stdio.h>
#include <alloc.h>
#include <mem.h>
int main(void)
{
   char *dest;
   dest = calloc(21, sizeof(char));
   setmem(dest, 20, 'c');
   printf("%s\n", dest);
   return 0;
}
 2.   setmode函数
setmode函数的功能是设置打开文件方式,其用法为int setmode(int handle, unsigned mode);程序实例代码如下:
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
   int result;
   result = setmode(fileno(stdprn), O_TEXT);
   if (result == -1)
      perror("Mode not available\n");
   else
     ......

C/C++——小编谈C语言函数那些事(23)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   settextstyle函数
settextstyle函数的功能是为图形输出设置当前的文本属性,其用法为:void far settextstyle (int font, int direction, char size);程序实例如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
char *fname[] = { "DEFAULT font",
                  "TRIPLEX font",
                  "SMALL font",
                  "SANS SERIF font",
                  "GOTHIC font"
          &nb ......

C/C++——小编谈C语言函数那些事(23)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   settextstyle函数
settextstyle函数的功能是为图形输出设置当前的文本属性,其用法为:void far settextstyle (int font, int direction, char size);程序实例如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
char *fname[] = { "DEFAULT font",
                  "TRIPLEX font",
                  "SMALL font",
                  "SANS SERIF font",
                  "GOTHIC font"
          &nb ......

C/C++——小编谈C语言函数那些事(24)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   setvect函数
setvect函数的功能是设置中断矢量入口,其用法为:void setvect(int intr_num, void interrupt(*isr)());程序实例如下:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
   count++;
   oldhandler();
}
int main(void)
{
   oldhandler = getvect(INTR);
   setvect(INTR, handler);
   while (count < 20)
      printf("count is %d\n",count);
   setvect(INTR, oldhandler);
   return 0;
}
 2.   setverify函数
setverify函数的功能是设置验证状态,其用法为void setverify(int value);程序实例代码如下:
#include <stdio.h>
#include <conio.h>
#include < ......

C/C++——小编谈C语言函数那些事(24)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   setvect函数
setvect函数的功能是设置中断矢量入口,其用法为:void setvect(int intr_num, void interrupt(*isr)());程序实例如下:
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#define INTR 0X1C
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
   count++;
   oldhandler();
}
int main(void)
{
   oldhandler = getvect(INTR);
   setvect(INTR, handler);
   while (count < 20)
      printf("count is %d\n",count);
   setvect(INTR, oldhandler);
   return 0;
}
 2.   setverify函数
setverify函数的功能是设置验证状态,其用法为void setverify(int value);程序实例代码如下:
#include <stdio.h>
#include <conio.h>
#include < ......

C/C++——小编谈C语言函数那些事(25)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   setwritemode函数
setwritemode函数的功能是设置图形方式下画线的输出模式,其用法为:void far setwritemode(int mode);程序实例如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;
   initgraph(&gdriver, &gmode, "");
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   xmax = getmaxx();
   ymax = getmaxy();
   setwritemode(XOR_PUT); ......

C/C++——小编谈C语言函数那些事(25)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   setwritemode函数
setwritemode函数的功能是设置图形方式下画线的输出模式,其用法为:void far setwritemode(int mode);程序实例如下:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main()
{
   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;
   initgraph(&gdriver, &gmode, "");
   errorcode = graphresult();
   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   xmax = getmaxx();
   ymax = getmaxy();
   setwritemode(XOR_PUT); ......
总记录数:969; 总页数:162; 每页6 条; 首页 上一页 [111] [112] [113] [114] 115 [116] [117] [118] [119] [120]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号