atoiを使って文字列から数字を抜き出すのがうまくいきません
Posted: 2013年2月14日(木) 13:27
メッセージの表示速度を命令があれば変更するプログラムを作ろうとしているのですが、atoiを使って文字列の中から数字の部分を抜き取って、数字に変換して命令を与えようとしているのですがうまくいきません。
どうしたら良いでしょうか?
---op.sの内容---
???:「@rs 400・・・・・・。@rs 200どうやら
---ソース---
#include "DxLib.h"
#define MOJI_SIZE 24 // 文字のサイズ
#define SCREEN_X 936 // 画面の横幅
#define SCREEN_Y 702 // 画面の縦幅
char script[10000]={0};//文字データ全体
char LoadFname[100];
int LoadFsize;
int DrawPointX , DrawPointY; // 文字列描画の位置
int CP; // 参照する文字列中の文字ポインタ
// 改行関数
int Kaigyou( int h ){
// 描画行位置を一つ下げる
DrawPointY ++;
if(h){
DrawPointX = 2 ;
}
else{
// 描画列を最初に戻す
DrawPointX = 1 ;}
return 0 ;
}
// テキストファイルのロード
int loadfile(char *filename){
int y=0;
int i=0;
int m=0;
bool sw=true;
char c;
FILE *fp;
for(i=0;i<100;i++){
LoadFname=NULL;
}//FILENAMEをNULLで初期化する。
for(i=0;i<100;i++){
if(filename!='\0'){
LoadFname=filename;
LoadFsize=i+1;
}
}
i=0;
fp = fopen(filename,"r");
if(fp!=NULL){
for( ; ; ){
c=fgetc(fp);
if( feof( fp ) ) {
break;
}
else if(script[i-1]=='/' && c=='/'){
script[ i-1]=0;
script[ i ]=0;
sw=false;
i-=1;
}
else if( c == '\n' ){
script='\0';
sw=true;
}
else if(sw==true){
script=c;
i++;
}
m=i;
}
}
fclose(fp);
return m;
}
int JC(unsigned char code){
if( (code >= 0x81 && code <= 0x9F) ||
(code >= 0xE0 && code <= 0xFC) ) {
return 1;
}
return 0;
}
void scriptOrder(int z){
CP=0;
bool sw=true;
bool b_sw=false;
char One[ 2 ];
char Two[ 3 ];
int kei=0;
int kio=0;
int i=0;
int j;
int g=NULL;
DrawPointX = 1 ;
DrawPointY = 23 ;
int h = LoadGraph("ren_ga.gph");
int m = LoadGraph("mado.gph");
int n = LoadGraph("name_g.bmp");
int kF = LoadGraph("F.gph");
int kH = LoadGraph("H.gph");
SetDrawScreen(DX_SCREEN_BACK);
while( ProcessMessage() == 0 && CP < z ){
if( script[CP] == '@' ){
CP++;
//問題の箇所はここ
if(strnicmp(&script[ CP ],"rs",2)==0){
CP+=3;
if(isdigit(script[ CP ])){
g=atoi(&script[ CP ]);
j=1;
while(1){
if(isdigit(script[ CP + j ])){
g=atoi(&script[ CP + j ]);
}
else{
break;
}
j++;
}
WaitTimer( g ) ;
CP+=j;
}
}
}
else if( script[ CP ] == ':'){
DrawPointX = 1 ;
DrawPointY = 25 ;
sw=false;
Two[ 0 ] = script[ CP + 1 ];
Two[ 1 ] = script[ CP + 2 ];
Two[ 2 ] = '\0';
if( strcmp(Two,"「") == 0 ){
b_sw=true;
}
CP++;
}
else{
if(JC(script[CP])){
Two[ 0 ] = script[ CP ];
Two[ 1 ] = script[ CP + 1 ];
Two[ 2 ] = '\0';
if(sw){
DrawString( DrawPointX * MOJI_SIZE+12 , DrawPointY * MOJI_SIZE , Two , GetColor(255,255,255) ) ;
}
else{
DrawString( DrawPointX * MOJI_SIZE , DrawPointY * MOJI_SIZE , Two , GetColor(255,255,255) ) ;
}
ScreenFlip();
CP+=2;
}
else{
One[ 0 ] = script[ CP ];
One[ 1 ] = '\0';
if(sw){
DrawString( DrawPointX * MOJI_SIZE+12 , DrawPointY * MOJI_SIZE , One , GetColor(255,255,255) ) ;
}
else{
DrawString( DrawPointX * MOJI_SIZE , DrawPointY * MOJI_SIZE , One , GetColor(255,255,255) ) ;
}
ScreenFlip();
CP++;
}
// カーソルを一文字文進める
DrawPointX ++ ;
}
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){
int i=0;
int DrawPointX=0;
int DrawPointY=0; // 文字列描画の位置
int col=GetColor(255,255,255);
char fn[100]="op.s";
int z;
//ログを出力しない
SetOutApplicationLogValidFlag( FALSE );
SetGraphMode( SCREEN_X , SCREEN_Y , 16 ) ;
ChangeWindowMode(true);
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1; // エラーが起きたら直ちに終了
}
SetFontSize( MOJI_SIZE ) ;
z=loadfile(fn);
scriptOrder(z);
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}
どうしたら良いでしょうか?
---op.sの内容---
???:「@rs 400・・・・・・。@rs 200どうやら
---ソース---
#include "DxLib.h"
#define MOJI_SIZE 24 // 文字のサイズ
#define SCREEN_X 936 // 画面の横幅
#define SCREEN_Y 702 // 画面の縦幅
char script[10000]={0};//文字データ全体
char LoadFname[100];
int LoadFsize;
int DrawPointX , DrawPointY; // 文字列描画の位置
int CP; // 参照する文字列中の文字ポインタ
// 改行関数
int Kaigyou( int h ){
// 描画行位置を一つ下げる
DrawPointY ++;
if(h){
DrawPointX = 2 ;
}
else{
// 描画列を最初に戻す
DrawPointX = 1 ;}
return 0 ;
}
// テキストファイルのロード
int loadfile(char *filename){
int y=0;
int i=0;
int m=0;
bool sw=true;
char c;
FILE *fp;
for(i=0;i<100;i++){
LoadFname=NULL;
}//FILENAMEをNULLで初期化する。
for(i=0;i<100;i++){
if(filename!='\0'){
LoadFname=filename;
LoadFsize=i+1;
}
}
i=0;
fp = fopen(filename,"r");
if(fp!=NULL){
for( ; ; ){
c=fgetc(fp);
if( feof( fp ) ) {
break;
}
else if(script[i-1]=='/' && c=='/'){
script[ i-1]=0;
script[ i ]=0;
sw=false;
i-=1;
}
else if( c == '\n' ){
script='\0';
sw=true;
}
else if(sw==true){
script=c;
i++;
}
m=i;
}
}
fclose(fp);
return m;
}
int JC(unsigned char code){
if( (code >= 0x81 && code <= 0x9F) ||
(code >= 0xE0 && code <= 0xFC) ) {
return 1;
}
return 0;
}
void scriptOrder(int z){
CP=0;
bool sw=true;
bool b_sw=false;
char One[ 2 ];
char Two[ 3 ];
int kei=0;
int kio=0;
int i=0;
int j;
int g=NULL;
DrawPointX = 1 ;
DrawPointY = 23 ;
int h = LoadGraph("ren_ga.gph");
int m = LoadGraph("mado.gph");
int n = LoadGraph("name_g.bmp");
int kF = LoadGraph("F.gph");
int kH = LoadGraph("H.gph");
SetDrawScreen(DX_SCREEN_BACK);
while( ProcessMessage() == 0 && CP < z ){
if( script[CP] == '@' ){
CP++;
//問題の箇所はここ
if(strnicmp(&script[ CP ],"rs",2)==0){
CP+=3;
if(isdigit(script[ CP ])){
g=atoi(&script[ CP ]);
j=1;
while(1){
if(isdigit(script[ CP + j ])){
g=atoi(&script[ CP + j ]);
}
else{
break;
}
j++;
}
WaitTimer( g ) ;
CP+=j;
}
}
}
else if( script[ CP ] == ':'){
DrawPointX = 1 ;
DrawPointY = 25 ;
sw=false;
Two[ 0 ] = script[ CP + 1 ];
Two[ 1 ] = script[ CP + 2 ];
Two[ 2 ] = '\0';
if( strcmp(Two,"「") == 0 ){
b_sw=true;
}
CP++;
}
else{
if(JC(script[CP])){
Two[ 0 ] = script[ CP ];
Two[ 1 ] = script[ CP + 1 ];
Two[ 2 ] = '\0';
if(sw){
DrawString( DrawPointX * MOJI_SIZE+12 , DrawPointY * MOJI_SIZE , Two , GetColor(255,255,255) ) ;
}
else{
DrawString( DrawPointX * MOJI_SIZE , DrawPointY * MOJI_SIZE , Two , GetColor(255,255,255) ) ;
}
ScreenFlip();
CP+=2;
}
else{
One[ 0 ] = script[ CP ];
One[ 1 ] = '\0';
if(sw){
DrawString( DrawPointX * MOJI_SIZE+12 , DrawPointY * MOJI_SIZE , One , GetColor(255,255,255) ) ;
}
else{
DrawString( DrawPointX * MOJI_SIZE , DrawPointY * MOJI_SIZE , One , GetColor(255,255,255) ) ;
}
ScreenFlip();
CP++;
}
// カーソルを一文字文進める
DrawPointX ++ ;
}
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ){
int i=0;
int DrawPointX=0;
int DrawPointY=0; // 文字列描画の位置
int col=GetColor(255,255,255);
char fn[100]="op.s";
int z;
//ログを出力しない
SetOutApplicationLogValidFlag( FALSE );
SetGraphMode( SCREEN_X , SCREEN_Y , 16 ) ;
ChangeWindowMode(true);
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1; // エラーが起きたら直ちに終了
}
SetFontSize( MOJI_SIZE ) ;
z=loadfile(fn);
scriptOrder(z);
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}