小编0x6*_*C74的帖子

将所有255个ASCII/ANSI/ISO字符输出到文件中

#include <stdio.h>
#include <iostream>


int main()
{
    FILE* oFile=fopen("file","wb");

    for(int i = 255; i>=0; i--)
        fprintf(oFile,"%c",i);

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

现在,"文件"只包含"怪异"字符:

훗퓕틓탑컏쳍쫋죉웇쓅싃상뺿벽못뢹뚷뒵늳낱꺯겭ꪫꢩꚧ꒥ꊣꂡ麟鲝骛颙隗钕铨邑躏狸誋袉蚇蒅芃肁繿籽穻硹癷瑵牳灱汤汭横桩晧摥扣恡帜屝婛塙噗呕剓偑乏䱍䩋䡉䙇䑅䉃䁁㸿㰽㨻㠹㘷㐵㈳〱ⸯⰭ⨫⠩☧␥|‡ḟᰝᨛ᠙ᘗᐕሓထฏ఍਋ࠉ؇Ѕȃ

对我来说很有趣,使用控制台流,一切都很好.

#include <stdio.h>
#include <iostream>




int main()
{


    for(int i = 255; i>=0; i--)
        printf("%c",i);

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题是:为什么输出文件中没有"拉丁"字符?即使在从UCS-2小端(为什么自动选择?)转换为记事本++中的ascii之后:

DLD«»DLAD>·d"μD<LD±I»自力««IL©I>§î"AI <LII»źíłťí«> IL™I> -I"•I <"í'ě»ŹěłŤě« <EL‰E>‡E"... E <ě뺿벽못EAES·ë'μ늳ë,±ęşŻę˛ęŞ«E©ęš§ę'ĄęŠŁę,麟鲝éŞ>电子™ES-E'• ES"é,'躏貍čŞ<C‰‡CS C'......čŠč,çążç±ç©»CAC™·ç'μç‰LC±ćąŻć±ć©«C©C™§ć'Ąć‰Łćĺąźĺ± ťĺ©>ĺ™ĺ™-ĺ'•ĺ‰"ĺ'ä±ää±ää©<ä‰ä™‡ää...ä‰ä㸿㰽㨻ă±ăƒăăăă€â€œâââââââââ↨«ââââââââââââââââââââââ€''''á'á'áááá•"ŹŕŤŕŤŕ<<<<

c file

1
推荐指数
2
解决办法
504
查看次数

确保字符串只包含某些带有正则表达式的单词

我想使用 Java 中的正则表达式来验证字符串的格式是否正确。如果字符串包含的唯一单词来自指定列表,则该字符串的格式正确。一个单词可以包含大写和小写字母。字符串可以包含数字和符号。

例如,如果我的接受词列表是[foo, bar],那么字符串

foo bar! bar foo.
Run Code Online (Sandbox Code Playgroud)

已验证。请注意,字符串不必包含 lsit 中的每个单词。因此字符串foo是有效的,字符串bar也是有效的。

像一个字符串

foo bar baz!
Run Code Online (Sandbox Code Playgroud)

是无效的。

java regex

1
推荐指数
1
解决办法
1337
查看次数

"TCHAR cFileName [MAX_PATH];" - MSDN库中的错误?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365740%28v=vs.85%29.aspx

cFileName
文件的名称.

的值MAX_PATH相同的几乎相同_MAX_FNAME,但使用第一是在这种情况下产生误导.无论如何,如果他们的意思是完整的名字,那应该是cFileName[MAX_PATH+_MAX_FNAME];吗?使用目的是MAX_PATH什么?

windows winapi msdn

1
推荐指数
1
解决办法
1270
查看次数

使用单个复选框动态禁用一堆文本框

MainWindow.xaml

<CheckBox Content="Enable" Height="16" HorizontalAlignment="Left" Margin="190,40,0,0" Name="checkBox_Enable" VerticalAlignment="Top" IsChecked="True" Unchecked="checkBox_Enable_Unchecked" Checked="checkBox_Enable_Checked" />
    <Label Content="Fullscreen:" Height="15" HorizontalAlignment="Left" Margin="227,63,0,0" Name="label3" VerticalAlignment="Top" Width="56" Padding="1" />
    <TextBox HorizontalAlignment="Right" Margin="0,86,243,0" Name="textBox_Hotkey_Fullscreen" Width="33" Height="18" VerticalAlignment="Top" />
    <Label Content="Custom field:" HorizontalAlignment="Left" Margin="227,110,0,136" Name="label5" Padding="1" />
    <TextBox Height="18" HorizontalAlignment="Left" Margin="227,131,0,0" Name="textBox_Hotkey_Customfield" VerticalAlignment="Top" Width="33" />
    <Label Content="Window-related:" HorizontalAlignment="Left" Margin="227,155,0,87" Name="label4" Padding="1" />
    <TextBox HorizontalAlignment="Left" Margin="227,0,0,112" Name="textBox_Hotkey_Windowrelated" Width="33" Height="18" VerticalAlignment="Bottom"  />
Run Code Online (Sandbox Code Playgroud)

MainWindow.xaml.cs

    private void checkBox_Enable_Unchecked(object sender, RoutedEventArgs e)
    {
        textBox_Hotkey_Fullscreen.IsEnabled = false;
        textBox_Hotkey_Customfield.IsEnabled = false;
        textBox_Hotkey_Windowrelated.IsEnabled = false;
    }

    //There …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

1
推荐指数
1
解决办法
124
查看次数

制作宽字符文件

#ifndef UNICODE
#define UNICODE
#endif

#include <stdio.h>
int main()
{
    FILE* oFile;
    oFile = _wfopen(L"foo.txt",L"w");
    //*
    fwprintf(oFile,L"%s", L"??ó????•?");
    fclose(oFile);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么这个程序创建一个ASCII文件而不是UTF-16,虽然所有函数都很宽?!

foo.txt内容:

za [问号]ó[两个问号...] g [...四...] ja [另外两个......] [五个??] [和最后一个]

这是不可兑现的.

fwprintf(oFile,L"%c%c%s",0xFE,0xFF,L"za?ó?? g???? ja?? ????• ?");
Run Code Online (Sandbox Code Playgroud)

现在,它显示中文符号,无论是否设置了小字节或大字节顺序标记.

c windows unicode

0
推荐指数
1
解决办法
1244
查看次数

因子函数为高参数产生不正确的值

这个小程序测试了两种计算阶乘的方法 - 迭代和递归.

Factorial.cs:

using System;

namespace Functions
{
    public class Factorial
    {
        public static ulong CalcRecursively(int number)
        {
            if (number > 1)
                return (ulong)number * CalcRecursively(number - 1);
            if (number <= 1)
                return 1;

            return 0;
        }

        public static ulong Calc(int number)
        {
            ulong rValue=1;

            for (int i = 0; i < number; i++)
            {
                rValue = rValue * (ulong)(number - i);                
            }

            return rValue;

        }


    }
}
Run Code Online (Sandbox Code Playgroud)

MainProgram.cs:

using System;

using Functions;
class FunctionClient
{


    public static void …
Run Code Online (Sandbox Code Playgroud)

c# console console-application factorial

0
推荐指数
1
解决办法
646
查看次数

崩溃遍历双重链表

typedef struct tape
{
    char symbol;
    struct tape *next;
    struct tape *prev;
}tape;

tape *pt;    

void GenerateInputTape(int n)
{
    int i;

    pt=(tape*)malloc(sizeof(tape));

    pt->symbol='B';

    pt->prev=NULL;
    pt->next=(tape*)malloc(sizeof(tape));
    pt=pt->next;

    for(i=0;i<2*(n+1);i++)
    {   
        if(i < (2*n/2))
            pt->symbol='0';
        else
            pt->symbol='1';

        pt->prev=pt;
        pt->next=(tape*)malloc(sizeof(tape));
        pt=pt->next;
    }

    pt->symbol='B';

    pt->next=NULL;
}

void ShowTape()
{
    //Move tape to the beginning
    while (pt->prev != NULL)
        pt=pt->prev; //crash point

    //List out all of the elements
    while ((pt->next) != NULL)
    {   
        printf("%c",pt->symbol);
        pt=pt->next;
    }
    puts("\n");
}
Run Code Online (Sandbox Code Playgroud)

这是一个程序的代码片段,旨在创建一个双向链表,用B0 ... n011 ....(n + 1)1B字符填充并打印它们.不幸的是,它在穿越时崩溃了.为什么?

turing_machine.exe中0x771a15de处的未处理异常:0xC0000005:访问冲突读取位置0xcdcdcdd5.

c linked-list doubly-linked-list

0
推荐指数
1
解决办法
180
查看次数

在绘画上分层按钮

有一个窗口,我想在其中放置一个按钮,然后在其下面绘制整个区域.换句话说,按钮应该覆盖一块画.

import java.awt.*;
import javax.swing.*;

class Window
{
    private JFrame frame;
    private JButton launchButton;
    private JPanel pnllaunchButton;
    private JPanel paintingPanel;
    //width and height of client area
    private Rectangle dim;

    //w,h - width and height of the whole window 
    public Window(String title,int w,int h)
    {  
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(0,0);
        frame.setMinimumSize( new Dimension(110,110));
        frame.setSize(w, h);
        frame.setVisible(true);
        frame.setTitle(title);           
        frame.setResizable(false);

        addLaunchButton();
    }        

    private void addLaunchButton()
    {   
        pnllaunchButton = new JPanel();
        launchButton = new JButton("Plot!");
        dim = new Rectangle();

        frame.getContentPane().getBounds(dim);

        pnllaunchButton.setBounds(dim.width-100,dim.height-25,100,25);

        launchButton.setBounds(dim.width-100,dim.height-25,100,25);

        pnllaunchButton.setLayout(null); …
Run Code Online (Sandbox Code Playgroud)

java swing

0
推荐指数
1
解决办法
404
查看次数

如何指定目标文件的名称

当我直观地尝试运行这样的命令时

cc -c source.c header.h -o a_name_different_than_source.o
Run Code Online (Sandbox Code Playgroud)

抛出以下错误

cc:无法使用多个文件为-o指定-c,-S或-E

c linux gcc cc

-4
推荐指数
1
解决办法
81
查看次数

启动没有表单的PHP脚本

我之前从未见过这样的方法,但我想知道为什么在单击"Say hello"按钮后没有任何反应.

<html>
<head>    
</head>
<body>
<button onclick="myscript.php">Say hello</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
<?php
echo "Hello";
?>
Run Code Online (Sandbox Code Playgroud)

如果我在这种情况下使用"形式"标记构造,它看起来会非常"夸张".
你能指出我的错误吗?或者,如果我的愿景完全没有希望,那么运行php脚本的非常规方法是什么?

html php

-9
推荐指数
2
解决办法
2594
查看次数