アニメ!アニメ!

2015年10月26日月曜日

C言語 sprintf

#include <stdio.h>
#include <string.h>
#include <cstring> //C++言語

int main()
{
//2015年10月26日と表示したい
printf("%d年%d月%d日\n", 2015, 10, 26);

//2015年12月3日と表示したい
printf("%d年%d月%d日\n", 2015, 12, 3);

//8桁指定で2015を表示する
// ただし、桁が足りない場合は0で埋めること
printf("%08d\n", 2015);


//1を左揃えで表示したい
printf("%-08d\n", 2015);

// sprintf  (string
char text[256];
sprintf_s(text, "%08d\n", 2015);

//sprintf_sでバッフォーオーバーランを防ぐ


"c:/dah/dk.ahg/dafs/ab...c.txt"

printf(text);
return 0;
}
// %d decuval 10進数
// %O octal 8進数

// %s string 文字列
// %x hexa decival 16進数
// %f float 浮動小数点数
// %c charcter 文字列
// \t tab タブ
// \a alert 警告音
// \b backspace バックスペース
// \r rewind 復帰
// \f feed 改ページ
// \\ \を文字として表示する
// \n 改行 new line 改行
// \0 null terminater null文字

// フィールド幅指定
// ゼロフィールド指定
//printf関数
//第一引数 書式付き文字列

2015年10月22日木曜日

「サーバーからの情報の取得中にエラーが発生しました。 RPC:S-7:AEC-0」

「サーバーからの情報の取得中にエラーが発生しました。 RPC:S-7:AEC-0」??

http://www.sumaho-etc.net/?p=227

2015年10月16日金曜日

[C#]文字列の数値への変換

using System;

class triangle
{
    public static void Main()
    {
        double 底辺, 高さ, 面積;
        string teihen, takasa;
        while (true)
        {
            Console.Write("高さ=");
            takasa = Console.ReadLine();
            高さ = double.Parse(takasa);
            if (高さ == 0.0)
                break;
            Console.Write("底辺 = ");
            teihen = Console.ReadLine();
            底辺 = double.Parse(teihen);
            面積 = 底辺 * 高さ / 2.0;
            Console.WriteLine("高さ{0}、底辺{1}の三角形の面積{2}です。",
                高さ, 底辺, 面積);
        }
    }
}

[C#]ReadLineメソッド

using System;

class Console03
{
    public static int Main()
    {
        Console.Write("あなたの名前は ");
        string YourName = Console.ReadLine();
        Console.Write("あなたの年齢は ");
        string YourAge = Console.ReadLine();
        Console.WriteLine("あなたの名前は{0}で年齢は{1}歳です",
            YourName, YourAge);

        return 0;
    }
}

[C#]WriteLineメソッドとインデックス

using System;

class console02
{
    public static int Main()
    {
        string cat = "猫" , dog = "犬";

            Console.WriteLine("{0}はあほですが、{1}は賢いです",cat,dog);
        return 0;
    }
}

http://www.kumei.ne.jp/c_lang/cs/cs_02.htm


C#プログラミングTips:文字列処理に関するヒント
http://www.atmarkit.co.jp/fdotnet/csharptips/010string/010string.html

[C#]Helloworld

using System;

class console01
{
    public static int Main()
    {
        Console.WriteLine("Helloworld!");

        return 0;
    }
}

2015年10月10日土曜日

[Windowプログラミング]文字を表示する

#include <Windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE, int)
{
char szClassName[] = "text01";

int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
LPSTR lpsCmdLine, int nCmdShow);
{
MSG msg;
BOOL bRet;

if (!InitApp(hCurInst))
return FALSE;
if (!InitInstance, nCmdShow)
return FALSE;
while (bRet = GetMessage(&msg, NULL, 0, 0)) != 0){
{
if (bRet == -1){
break;
}
}
else{
TranslateMessage(&mag);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}

ATOM InitApp(HINSTANCE hInst)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;

wc.hInstance = hInst;
wc.hIcon = (HICON)LoadImage(NULL,
MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL; wc.lpszClassName = NULL;
wc.lpszClassName = (LPCSTR)szClassName;
wc.hIconSm = (HICON)LoadImage(NULL,
MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);

return (RegisterClassEx)hInst, nCmdShow);
}
{
HWND nWnd;

hWnd = CreateWindow(szClassName,
"猫でもわかるテキスト表示",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
int id, u = 0, i;
PAINTSTRUCT ps;
HDC hdc;
char * lpszStr = "猫でもわかるゲームプログラミング";

switch (msg)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
for (i = 0; i < 20; i++){
TextOut(hdc, 0, y + 20 * i,
lpszStr, (int)strlen(lpszStr));
}
EndPaint(hWnd, &ps);
break;
case WM_CLOSE:
id = MassageBox(nWnd, "終了してもよろしいですか",
"終了確認", MB_YESNO);
if (id == IDYES)
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}

2015年10月6日火曜日

[C言語]Windowsプログラミング

#include <windows.h>
#pragma comment (lib, "winmm.lib")
#define _CRT_SECURE_NO_WARNINGS
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);

char szClassName[] = "template"; //ウィンドウクラス


int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow)
{
MSG msg;
BOOL bRet;

if (!InitApp(hCurInst))
return FALSE;
if (!InitInstance(hCurInst, nCmdShow))
return FALSE;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0){
if (bRet == -1){
break;
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}

//ウィンドウクラスの登録

ATOM InitApp(HINSTANCE hInst)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc; //プロシャージ名
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst; //インスタンス
wc.hIcon = (HICON)LoadImage(NULL,
MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_CURSOR,
0,
0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = NULL;
wc.lpszClassName = (LPCWSTR)szClassName;
wc.hIconSm = (HICON)LoadImage(NULL,
MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON,
0,
0,
LR_DEFAULTSIZE | LR_SHARED);

return (RegisterClassEx(&wc));
}

BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
{
HWND hWnd;

hWnd = CreateWindowA(szClassName,
"猫でも分かるWindowsプログラミング",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,

hInst,
NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

LRESULT CALLBACK WndProc(
HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
int id;

switch (msg)
{
case WM_CLOSE:
id = MessageBoxA(hWnd,
"終了しまてもよろしいですか",
"確認",
MB_YESNO | MB_ICONQUESTION);
if (id == IDYES)
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}


エラー 1 error LNK2019: 未解決の外部シンボル _main が関数 ___tmainCRTStartup で参照されました。 c:\Users\tyosuke\documents\visual studio 2013\Projects\ConsoleApplication106\ConsoleApplication106\MSVCRTD.lib(crtexe.obj) ConsoleApplication106

Visual Studioアプリケーションの種類を変更する方法
http://blogs.osdn.jp/programming/2015/02/24/subsystem.html