當前位置:首頁 » 編程語言 » c語言字元串處理

c語言字元串處理

發布時間: 2022-09-27 16:01:20

c語言中有哪些字元串處理函數

你可以看一下頭文件string.h和stdio.h裡面的相關函數聲明,好多好多。
這里就不一一列出了……比如下面列出的只是其中一部分……
_CRTIMP char * __cdecl strcpy(char *, const char *);
_CRTIMP char * __cdecl strcat(char *, const char *);
_CRTIMP int __cdecl strcmp(const char *, const char *);
_CRTIMP size_t __cdecl strlen(const char *);
_CRTIMP char * __cdecl strchr(const char *, int);
_CRTIMP int __cdecl _strcmpi(const char *, const char *);
_CRTIMP int __cdecl _stricmp(const char *, const char *);
_CRTIMP int __cdecl strcoll(const char *, const char *);
_CRTIMP int __cdecl _stricoll(const char *, const char *);
_CRTIMP int __cdecl _strncoll(const char *, const char *, size_t);
_CRTIMP int __cdecl _strnicoll(const char *, const char *, size_t);
_CRTIMP size_t __cdecl strcspn(const char *, const char *);
_CRTIMP char * __cdecl _strp(const char *);
_CRTIMP char * __cdecl _strerror(const char *);
_CRTIMP char * __cdecl strerror(int);
_CRTIMP char * __cdecl _strlwr(char *);
_CRTIMP char * __cdecl strncat(char *, const char *, size_t);
_CRTIMP int __cdecl strncmp(const char *, const char *, size_t);
_CRTIMP int __cdecl _strnicmp(const char *, const char *, size_t);
_CRTIMP char * __cdecl strncpy(char *, const char *, size_t);
_CRTIMP char * __cdecl _strnset(char *, int, size_t);
_CRTIMP char * __cdecl strpbrk(const char *, const char *);
_CRTIMP char * __cdecl strrchr(const char *, int);
_CRTIMP char * __cdecl _strrev(char *);
_CRTIMP size_t __cdecl strspn(const char *, const char *);
_CRTIMP char * __cdecl strstr(const char *, const char *);
_CRTIMP char * __cdecl strtok(char *, const char *);
_CRTIMP char * __cdecl _strupr(char *);
_CRTIMP size_t __cdecl strxfrm (char *, const char *, size_t);

Ⅱ C語言程序設計 字元串處理

子字元串之間可以用'\n』來分隔,以實現子串的定位,偽代碼可以這樣: #include <stdio.h> #include <fcntl.h> #include <string.h> #include <unstdio.h> int count(char str,int i) { if(遇到『\n』) i++; return i; }; int chang() { }; void() { }; main() { int a,b,c; 請輸入要選擇操作的編號1-4; switch{ case 1:count();break; 2: change();break; 3: del();break; 4: exit(); } }

Ⅲ C語言程序設計:字元串處理操作。條件:(不使用系統庫函數)編寫函數實現對字元串進行常用操作處理,包括

對棧頂的兩個值(或者一個,比如取反)做一次數學或位操作。 其中,棧頂的那個值是第二個操作數。 它會彈出壓入的值,並把結果放在棧頂。 這個函數遵循 L ua 對應的操作符
設置一個新的 panic 函數,並返回之前設置的那個。
調用一個函數。
要調用一個函數請遵循以下協議: 首先,要調用的函數應該被壓入棧; 接著,把需要傳遞給這個函數的參數按正序壓棧; 這是指第一個參數首先壓棧。 最後調用一下 lua_call; nargs 是你壓入棧的參數個數。 當函數調用完畢後,所有的參數以及函數本身都會出棧。 而函數的返回值這時則被壓棧。 返回值的個數將被調整為 nresults 個, 除非 nresults 被設置成 LUA_MULTRET。 在這種情況下,所有的返回值都被壓入堆棧中。 Lua 會保證返回值都放入棧空間中。 函數返回值將按正序壓棧(第一個返回值首先壓棧), 因此在調用結束後,最後一個返回值將被放在棧頂。
被調用函數內發生的錯誤將(通過 longjmp )一直上拋。
為了正確的和 Lua 通訊, C 函數必須使用下列協議。 這個協議定義了參數以及返回值傳遞方法: C 函數通過 Lua 中的棧來接受參數, 參數以正序入棧(第一個參數首先入棧)。 因此,當函數開始的時候, lu a_gettop(L) 可以返回函數收到的參數個數。 第一個參數(如果有的話)在索引 1 的地方, 而最後一個參數在索引 lua_gettop(L) 處。 當需要向 Lu a 返回值的時候, C 函數只需要把它們以正序壓到堆棧上(第一個返回值最先壓入), 然後返回這些返回值的個數。 在這些返回值之下的,堆棧上的東西都會被 L ua 丟掉。 和 L ua 函數一樣,從 Lua 中調用 C 函數也可以有很多返回值。

Ⅳ 在C語言中處理字元的幾種常用方法

基本上兩種:字元數組和字元指針。字元數組名是常量,字元指針是變數
1、用字元數組:一個一維字元數組存儲一個字元串,二維數組存儲多個字元串。如:
int i;
char s1[]="abc",s2[][80]={"ABCD","XYZ"},s3[80];
scanf("%s",s3);
printf("%s,%s\n",s1,s3);
for(i=0;i<2;i++)printf("%s\n",s2[i]);
2、用字元指針:字元指針指向一個字元串,字元指針數組處理多個字元串。如:
int i;
char *p1="abc",*p2[]={"ABCD","XYZ"},**p;
printf("%s\n",p1);
for(i=0;i<2;i++)printf("%s\n",p2[i]);
p=p2;
for(i=0;i<2;i++)printf("%s\n",*p++);
3、字元數組與字元指針配合一起使用:字元數組提供字元串的存儲,處理字元串用字元指針
char s[80],*p;
p=s;
scanf("%s",p);
printf("%s",p);
在string.h中所有處理字元串函數,對字元數組和字元指針都適用。

Ⅳ c語言編程:字元串處理


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
intsortArr(int*arr,intcount)
{
inti=0,j=0,tmp;
for(i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
if(arr[i]>arr[j])
{
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
}

}
}
return0;
}
voidmain()
{
intrv=0;
intbuf[300]={0};
intcount=0;
inti=0;
chartmp;
intnum=0;
FILE*fp1=fopen("1.txt","r");
FILE*fp2=fopen("2.txt","r");
FILE*fp3=fopen("3.txt","w+");
if(fp1==NULL||fp2==NULL)
{
printf("文件打開失敗 ");
rv=-1;
gotoEnd;
}
while(!feof(fp1))
{
fscanf(fp1,"%d",&buf[count++]);
}
fclose(fp1);
while(!feof(fp2))
{
fscanf(fp2,"%d",&buf[count++]);
}
fclose(fp2);
sortArr(buf,count);
for(i=0;i<count;i++)
{
fprintf(fp3,"%d ",buf[i]);
}
fclose(fp3);
End:
system("pause");
}

Ⅵ C語言中給輸入的字元串分段處理

char
a[1024];
for(int
i
=
0;
i
<
1024;
i
++
)
{
scanf("%c",&a[i]);
//輸入字元串到一個數組中
if(a[i]
=
'\n');
//當你安回車鍵時,表示輸入的字元串借宿用break
跳出,循環
{
break;
}
}

Ⅶ C語言字元串處理函數




其實那些字元串函數並不復雜。任何一個的實現都不出五行代碼:

char *strcpy( char *dst, const char *src ) {
char *destination = dst;
while( *dst++ = *src++ )
;
return destination;
}

char *strcat( char *dst, const char *src ) {
char *destination = dst;
while( *dst++ )
;
strcpy( --dst, src );
return destination;
}

int strcmp( const char *s1, const char *s2 ) {
for( ; *s1 == *s2; s1++, s2++ )
if( *s1 == '\0' ) return 0;
return *s1 - *s2;
}

unsigned strlen( const char *s ) {
const char *t = s;
while( *t++ )
;
return --t - s;
}


Ⅷ C語言字元串處理函數strcmp

strcmp是比較古老的函數了,它就是在檢查'\0'為結尾的字元串,你的字元數組位置為5時,沒有位置來存儲'\0',所以函數strcmp檢查時候不會停止,會繼續向後面檢查(後面的地址沒有賦值,都是隨機的數,直到遇見'0'),所以不會相等。

Ⅸ c語言字元串處理函數的英文原名

函數名: strrchr
功 能: 在串中查找指定字元的最後一個出現
用 法: char *strrchr(char *str, char c);
舉例:
[cpp] view plain
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'/');
printf("filename is %s",++ptr);
//運行結果:filename is lib1.so

函數名: strchr
功 能: 在串中查找指定字元的第一個出現
用 法: char *strchr(char *str, char c);
舉例:
[cpp] view plain
char fullname="./lib/lib1.so";
char *ptr;
ptr = strrchr(fullname,'.');
printf("after strchr() is %s",++ptr);
//運行結果:after strchr() is /lib/lib1.so

函數名: strtok
功 能: 在串中查找指定字元的第一個出現
用 法: char *strtok(char *s, char *delim);
說明:
1.strtok函數的實質上的處理是,strtok在s中查找包含在delim中的字元並用NULL(』/0′)來替換,直到找遍整個字元串。這句話有兩層含義:(1)每次調用strtok函數只能獲得一個分割單位。(2)要獲得所有的分割單元必須反復調用strtok函數。
2.strtok函數以後的調用時的需用NULL來替換s.
3.形參s(要分割的字元串)對應的變數應用char s[]=」….」形式,而不能用char *s=」….」形式。
舉例:
[cpp] view plain
void main()
{
char buf[]=」Golden Global View」;
char* token = strtok( buf, 」 「);
while( token != NULL )
{
printf( 」%s 「, token );
token = strtok( NULL, 」 「);
}
return 0;
}
/*其結果為:

Golden
Global
View
*/

Ⅹ c語言中有沒有字元串類型如何存放和處理字元串

沒有字元串類型,但是C語言中字元串實際就是多個字元鏈接在一起,所以可以用字元數組或者指針。可以這樣定義
char s[]="this is a string";
C語言也有string.h頭文件,使用這個頭文件可以直接這樣
string s="this is a string";
望採納

熱點內容
python函數圖像 發布:2024-04-25 10:17:29 瀏覽:913
提供華為雲雲資料庫 發布:2024-04-25 10:12:32 瀏覽:591
演算法設計手冊 發布:2024-04-25 10:03:24 瀏覽:80
linuxapache緩存 發布:2024-04-25 10:03:12 瀏覽:109
內務櫃密碼鎖去哪裡買 發布:2024-04-25 10:03:07 瀏覽:820
androidtimestamp 發布:2024-04-25 09:06:07 瀏覽:608
玩火影筆記本要什麼配置 發布:2024-04-25 08:34:59 瀏覽:209
sql性能監視器 發布:2024-04-25 08:21:48 瀏覽:832
吃雞ak配置什麼最好 發布:2024-04-25 08:15:46 瀏覽:447
firefox緩存目錄 發布:2024-04-25 08:00:31 瀏覽:940