【发布时间】:2023-03-25 14:40:01
【问题描述】:
我想获取一个包含字母和字符的字符串,然后只过滤掉字母。然后我想重用该字符串并将其放入数组中。我将如何在 C 中做到这一点?
我使用了isalpha(),但只使用了printf,而不是变量。
感谢您的帮助。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
int i;
string w = "name1234";
string new ="";
int length = strlen(w);
for (i=0; length > i; i++)
{
if (isalpha(w[i]))
{
new = w;
}
}
printf("This is the new one: %s\n", new); //it should be 'name' not 'name1234'
return 0;
}
【问题讨论】: