关于#c语言#的问题:

对于一段给定的汉字文本(含数字,中文标点符号)要求得到所有中文标点符号在文本中的位置并统计标点符号的总数

使用一个包含中文标点符号的字符数组,对文本中每一个字符判断是否中文标点:

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>

#define MAX_LEN 1000

int main() {
    setlocale(LC_ALL, ""); // 设置本地化环境
    wchar_t text[MAX_LEN];
    wprintf(L"请输入汉字文本:\n");
    fgetws(text, MAX_LEN, stdin);

    wchar_t chinesePunctuation[] = L",。、!?;:“”‘’()《》【】——";
    int count = 0;
    wprintf(L"中文标点符号的位置为:\n");
    for (int i = 0; i < wcslen(text); i++) {
        for (int j = 0; j < wcslen(chinesePunctuation); j++) {
            if (text[i] == chinesePunctuation[j]) {
                wprintf(L"%d ", i);
                count++;
                break;
            }
        }
    }
    wprintf(L"\n");
    wprintf(L"中文标点符号的总数为:%d\n", count);

    return 0;
}

非常感谢!