Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用c语言处理文件_C++_File - Fatal编程技术网

C++ 使用c语言处理文件

C++ 使用c语言处理文件,c++,file,C++,File,如何从字符串中删除每个不是字母的字符 从字符串a、f、4、h、b, 我需要一个输出afhbi。 请注意,我不想逗号和其他类似的迹象。 这是我到目前为止的代码,它不起作用,有什么提示吗 while((fgets(str,30,fpointer))!=NULL) { //i get a string for(i=0;i<strlen(str);i++)//going thru the string if(isalpha(str[i])){strcat(Need,str[i])

如何从字符串中删除每个不是字母的字符 从字符串
a、f、4、h、b
, 我需要一个输出
afhbi
。 请注意,我不想逗号和其他类似的迹象。 这是我到目前为止的代码,它不起作用,有什么提示吗

while((fgets(str,30,fpointer))!=NULL)
{ //i get a string

    for(i=0;i<strlen(str);i++)//going thru the string
    if(isalpha(str[i])){strcat(Need,str[i]);}
      //if the char is alpha put it in a new  string called Need
}
while((fgets(str,30,fpointer))!=NULL)
{//我得到一个字符串

对于(i=0;i您不想使用
strcat
将字符添加到数组中。这是为了将一个字符串附加到另一个字符串上。只需在数组中插入字符即可

int j = 0;    // Index of the new string
for(i = 0; i < strlen(str); i++) {   //going thru the string
    if(isalpha(str[i])) {
        Need[j++] = str[i];
    }
}
Need[j] = 0;   // Make sure you terminate the new string
int j=0;//新字符串的索引
对于(i=0;i
您也可以使用memmove执行类似操作。首先复制需要的字符串

Need = strdup(str);
p = Need;
q = str;
while (*q) {
    if (!isalpha(*q)) {
        len = strlen(p); 
        memmove(p, p + 1, len); // this will move the NULL terminator too
    } else {
        p++;
    }
    q++;
}
现在,所有丑陋的非角色都需要清理