#include #include #include #include #include // GW-BASIC MID$ LEFT$ RIGHT$ CHR$ ASC VAL STR$ SGN // Übersetzung in Microsoft Visual C++ 1.52 // Alles nur im Format von double und String char texein[258], eintex[258], texaus[258]; double texanf, texlan, texasc; // MID$( A$, B ) = C$ Einsetzen char* mei8( char meiein[258], char einein[258], double meianf ) { char meiaus[258]; double meizah, meilen, einlen; strcpy( meiaus, meiein ); meilen = (double)strlen( meiein ); einlen = (double)strlen( einein ); if( meianf < 1 ) { return( meiaus ); } if( meilen < 1 ) { return( meiaus ); } if( einlen < 1 ) { return( meiaus ); } if( meilen < meianf ) { return( meiaus ); } for( meizah = 0; meizah < einlen ; meizah++ ) { if( meiaus[ (int)meizah + (int)meianf - (int)1 ] < 1 ) { return( meiaus ); } meiaus[ (int)meizah + (int)meianf - (int)1 ] = einein[ (int)meizah ]; } return( meiaus ); } // A$ = MID$( B$, C, D ) Ausschneiden ist die haeufigste Anwendung char* mid8( char midein[258], double midanf, double midlan ) { char midaus[258]; double midzah, midlen; midlen = (double)strlen( midein ); if( midanf < 1 ) { strcpy( midaus, "" ); return( midaus ); } if( midlan < 1 ) { strcpy( midaus, "" ); return( midaus ); } if( midlen < 1 ) { strcpy( midaus, "" ); return( midaus ); } if( midlen < midanf ) { strcpy( midaus, "" ); return( midaus ); } for( midzah = 0; midzah < midlan ; midzah++ ) { midaus[ (int)midzah ] = midein[ (int)midzah + (int)midanf - (int)1 ]; if( midein[ (int)midzah + (int)midanf - (int)1 ] < 1 ) { return( midaus ); } } midaus[ (int)midlan ] = 0; return( midaus ); } // A$ = LEFT$( B$, C ) Linker Teil char* left8( char lefein[258], double leflan ) { char lefaus[258]; strcpy( lefaus, mid8( lefein, 1, leflan ) ); return( lefaus ); } // A$ = MID$( B$, C ) Teil ab dem C-ten Zeichen inclusive char* mab8( char mabein[258], double mabanf ) { char mabaus[258]; strcpy( mabaus, mid8( mabein, mabanf, 255 ) ); return( mabaus ); } // A$ = RIGHT$( B$, C ) Rechter Teil char* right8( char rigein[258], double riglan ) { char rigaus[258]; double riglen; riglen = (double)strlen( rigein ); strcpy( rigaus, mab8( rigein, riglen + 1 - riglan ) ); return( rigaus ); } // A$ = CHR$( B ) Zeichen aus ASCII als 1-Zeichen-String char* chr8( double chrein ) { char chraus[4]; chraus[ (int)0 ] = (int)chrein; chraus[ (int)1 ] = (int)0; return( chraus ); } // A = ASC( B$ ) ASCII aus 1 Zeichen oder dem ersten Zeichen eines Strings double asc8( char ascein[258] ) { double ascaus; ascaus = (double)ascein[ (int)0 ]; return( ascaus ); } // A = VAL( B$ ) Zahl aus String double val8( char valein[258] ) { double valaus; valaus = (double)atof( valein ); return( valaus ); } // A$ = STR$( B ) String aus Zahl char* str8( double strein ) { char straus[258], ausstr[258]; double lenstr; _gcvt( strein, 10, ausstr ); lenstr = (double)strlen( ausstr ); if( ausstr[ (int)lenstr - (int)1 ] == '.' ) { ausstr[ (int)lenstr - (int)1 ] = (int)0; } if( strein < 0 ) { strcpy( straus, "" ); } else { strcpy( straus, " " ); } strcat( straus, ausstr ); return( straus ); } // A = SGN( B ) Vorzeichen double sgn8( double sgnein ) { double sgnaus; sgnaus = 0; if( sgnein < 0 ) { sgnaus = -1; } if( sgnein > 0 ) { sgnaus = 1; } return( sgnaus ); } // Test und Vorführung void main( void ) { strcpy( texein, "ABCDEFGHIJ" ); texanf = 3; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 5; texlan = 1; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 0; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 3; texlan = 0; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "" ); texanf = 3; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 10; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 11; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 20; texlan = 6; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 3; texlan = 20; strcpy( texaus, mid8( texein, texanf, texlan ) ); printf( "MID$( %c%s%c, (%f), (%f) ) = %c%s%c \n", 34, texein, 34, texanf, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 7; strcpy( texaus, mab8( texein, texanf ) ); printf( "MAB$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texanf, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); strcpy( eintex, "WXYZ" ); texanf = 4; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); strcpy( eintex, "WXYZ" ); texanf = 0; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); strcpy( eintex, "WXYZ" ); texanf = 20; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); strcpy( texein, "" ); strcpy( eintex, "WXYZ" ); texanf = 4; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); strcpy( eintex, "" ); texanf = 4; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); strcpy( eintex, "WXYZMNOPQR" ); texanf = 4; strcpy( texaus, mei8( texein, eintex, texanf ) ); printf( "MEI$( %c%s%c, (%f) ) = %c%s%c = %c%s%c \n", 34, texein, 34, texanf, 34, eintex, 34, 34, texaus, 34 ); _getch(); strcpy( texein, "KLMNOPQRST" ); texlan = 4; strcpy( texaus, left8( texein, texlan ) ); printf( "LEFT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "KLMNOPQRST" ); texlan = 1; strcpy( texaus, left8( texein, texlan ) ); printf( "LEFT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "KLMNOPQRST" ); texlan = 0; strcpy( texaus, left8( texein, texlan ) ); printf( "LEFT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "" ); texlan = 4; strcpy( texaus, left8( texein, texlan ) ); printf( "LEFT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "KLMNOPQRST" ); texlan = 20; strcpy( texaus, left8( texein, texlan ) ); printf( "LEFT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texlan = 2; strcpy( texaus, right8( texein, texlan ) ); printf( "RIGHT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texlan = 8; strcpy( texaus, right8( texein, texlan ) ); printf( "RIGHT$( %c%s%c, (%f) ) = %c%s%c \n", 34, texein, 34, texlan, 34, texaus, 34 ); strcpy( texein, "ABCDEFGHIJ" ); texasc = asc8( texein ); printf( "ASC( %c%s%c ) = (%f) \n", 34, texein, 34, texasc ); strcpy( texein, "" ); texasc = asc8( texein ); printf( "ASC( %c%s%c ) = (%f) \n", 34, texein, 34, texasc ); strcpy( texein, "ABCDEFGHIJ" ); texanf = 3; texlan = 1; texasc = asc8( mid8( texein, texanf, texlan ) ); printf( "ASC( MID$( %c%s%c, (%f), (%f) ) ) = (%f) \n", 34, texein, 34, texanf, texlan, texasc ); texasc = 66; strcpy( texaus, chr8( texasc ) ); printf( "CHR$( (%f) ) = %c%s%c \n", texasc, 34, texaus, 34 ); strcpy( texein, "-12.34" ); texasc = val8( texein ); printf( "VAL( %c%s%c ) = (%f) \n", 34, texein, 34, texasc ); texasc = 12.34; strcpy( texaus, str8( texasc ) ); printf( "STR$( (%f) ) = %c%s%c \n", texasc, 34, texaus, 34 ); texasc = -12.34; strcpy( texaus, str8( texasc ) ); printf( "STR$( (%f) ) = %c%s%c \n", texasc, 34, texaus, 34 ); texasc = 1234; strcpy( texaus, str8( texasc ) ); printf( "STR$( (%f) ) = %c%s%c \n", texasc, 34, texaus, 34 ); texasc = 1234; strcpy( texaus, mab8( str8( texasc ), 2 ) ); printf( "MID$( STR$( (%f) ), 2 ) = %c%s%c \n", texasc, 34, texaus, 34 ); texanf = 5; texasc = sgn8( texanf ); printf( "SGN( (%f) ) = (%f) \n", texanf, texasc ); texanf = 0; texasc = sgn8( texanf ); printf( "SGN( (%f) ) = (%f) \n", texanf, texasc ); texanf = -5; texasc = sgn8( texanf ); printf( "SGN( (%f) ) = (%f) \n", texanf, texasc ); }