xapsx
asked on
error LNK2019
hi experts,
im trying to compile this: https://www.experts-exchange.com/questions/20079662/base-64-encoding-and-decoding.html
but it give me some problems:
Linking...
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug/64.exe : fatal error LNK1120: 1 unresolved externals
Im not sure if im doing something wrong when i create the project or if this is a problem in visual studio.Net 2003?
Can any1 help me out or send me the version compiled? i need it urgently
thanks a lot.
im trying to compile this: https://www.experts-exchange.com/questions/20079662/base-64-encoding-and-decoding.html
but it give me some problems:
Linking...
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug/64.exe : fatal error LNK1120: 1 unresolved externals
Im not sure if im doing something wrong when i create the project or if this is a problem in visual studio.Net 2003?
Can any1 help me out or send me the version compiled? i need it urgently
thanks a lot.
If you do have a 'main()' function, you probably set the wrong project type. If not, add one. If the project should be a GUI app (i.e. with a 'WinMain()'), go to your project settings, choose the 'Link' tab and locate '/subsystem:console' in the text field at the bottom of the dialog. Change that to '/subsystem:windows'
>>Can any1 help me out or send me the version compiled?
Sure, but what exactly from that link is what you need to have compiled?
Sure, but what exactly from that link is what you need to have compiled?
ASKER
what u whant, i need a working base64 decode & encode. thanks
//code.cpp
int main()
{
return 0;
}
Project->Settings->Link(Ta b)->Projec t Options(ListBox)
chnage /subsystem:windows to /subsystem:console
_novi_
int main()
{
return 0;
}
Project->Settings->Link(Ta
chnage /subsystem:windows to /subsystem:console
_novi_
ASKER
i've gone to:
Configuration Propreties>Linker>System ->
SubSystem = Console (/SUBSYSTEM:CONSOLE)
what is wrong?
thanks!
Configuration Propreties>Linker>System ->
SubSystem = Console (/SUBSYSTEM:CONSOLE)
what is wrong?
thanks!
Are you having a 'main()', then?
You should 'wrap' the relevant code into one, e.g.
#include <stdio.h>
äinclude <string.h>
#include <stdlib.h>
static char* _cpBase64Encoding =
"ABCDEFGHIJKLMNOPQRSTUVWXY Zabcdefghi jklmnopqrs tuvwxyz012 3456789+/= ";
void Base64Encode( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ]; // will contain the indices of coded letters in
// _cpBase64Encoding string; valid values [0..64]; the value
// of 64 has special meaning - the padding symbol
// process the data (3 bytes of input provide 4 bytes of output)
while ( '\0' != *cpInput )
{
nIdx[0] = ((*cpInput) & 0xFC)>>2;
nIdx[1] = ((*cpInput) & 0x03)<<4;
cpInput++;
if ( '\0' != *cpInput )
{
nIdx[1] |= ((*cpInput) & 0xF0)>>4;
nIdx[2] = ((*cpInput) & 0x0F)<<2;
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[2] |= ((*cpInput) & 0xC0) >> 6;
nIdx[3] = (*cpInput) & 0x3F;
cpInput++;
}
else
nIdx[3] = 64;
}
else
{ // refer to padding symbol '='
nIdx[2] = 64;
nIdx[3] = 64;
}
*(cpOutput+0) = *(_cpBase64Encoding + nIdx[0]);
*(cpOutput+1) = *(_cpBase64Encoding + nIdx[1]);
*(cpOutput+2) = *(_cpBase64Encoding + nIdx[2]);
*(cpOutput+3) = *(_cpBase64Encoding + nIdx[3]);
cpOutput += 4;
}
// set this to terminate output string
*cpOutput = '\0';
return;
}
void Base64Decode( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ]; // will contain the indices of coded letters in
// _cpBase64Encoding string; valid values [0..64]; the value
// of 64 has special meaning - the padding symbol
// process the data (3 bytes of input provide 4 bytes of output
while ( '\0' != *cpInput )
{
nIdx[ 0 ] = nIdx[ 1 ] = nIdx[ 2 ] = nIdx[ 3 ] = 64;
nIdx[0] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != *cpInput )
{
nIdx[1] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[2] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[3] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
}
}
}
if ( nIdx[3] == 64 ) nIdx[3] = 0;
if ( nIdx[2] == 64 ) nIdx[2] = 0;
if ( nIdx[1] == 64 ) nIdx[1] = 0;
*(cpOutput+0) = (char)((nIdx[0]<<2) | (nIdx[1]>>4));
*(cpOutput+1) = (char)((nIdx[1]<<4) | (nIdx[2]>>2));
*(cpOutput+2) = (char)((nIdx[2]<<6) | nIdx[3]);
cpOutput += 3;
}
// set this to terminate output string
*cpOutput = '\0';
return;
}
void main () {
char sNonCoded[ 256 ];
char sEncoded[ 256 ];
strcpy( sNonCoded, "This is non-coded text" );
Base64Encode( sNonCoded, sEncoded );
printf( "Encoded: %s", sEncoded );
Base64Decode( sEncoded, sNonCoded );
printf( "Decoded back: %s", sNonCoded );
}
You should 'wrap' the relevant code into one, e.g.
#include <stdio.h>
äinclude <string.h>
#include <stdlib.h>
static char* _cpBase64Encoding =
"ABCDEFGHIJKLMNOPQRSTUVWXY
void Base64Encode( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ]; // will contain the indices of coded letters in
// _cpBase64Encoding string; valid values [0..64]; the value
// of 64 has special meaning - the padding symbol
// process the data (3 bytes of input provide 4 bytes of output)
while ( '\0' != *cpInput )
{
nIdx[0] = ((*cpInput) & 0xFC)>>2;
nIdx[1] = ((*cpInput) & 0x03)<<4;
cpInput++;
if ( '\0' != *cpInput )
{
nIdx[1] |= ((*cpInput) & 0xF0)>>4;
nIdx[2] = ((*cpInput) & 0x0F)<<2;
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[2] |= ((*cpInput) & 0xC0) >> 6;
nIdx[3] = (*cpInput) & 0x3F;
cpInput++;
}
else
nIdx[3] = 64;
}
else
{ // refer to padding symbol '='
nIdx[2] = 64;
nIdx[3] = 64;
}
*(cpOutput+0) = *(_cpBase64Encoding + nIdx[0]);
*(cpOutput+1) = *(_cpBase64Encoding + nIdx[1]);
*(cpOutput+2) = *(_cpBase64Encoding + nIdx[2]);
*(cpOutput+3) = *(_cpBase64Encoding + nIdx[3]);
cpOutput += 4;
}
// set this to terminate output string
*cpOutput = '\0';
return;
}
void Base64Decode( char* cpInput, char* cpOutput )
{
int nIdx[ 4 ]; // will contain the indices of coded letters in
// _cpBase64Encoding string; valid values [0..64]; the value
// of 64 has special meaning - the padding symbol
// process the data (3 bytes of input provide 4 bytes of output
while ( '\0' != *cpInput )
{
nIdx[ 0 ] = nIdx[ 1 ] = nIdx[ 2 ] = nIdx[ 3 ] = 64;
nIdx[0] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != *cpInput )
{
nIdx[1] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[2] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
if ( '\0' != (*cpInput) )
{
nIdx[3] = (strchr( _cpBase64Encoding, (*cpInput) ) - _cpBase64Encoding);
cpInput++;
}
}
}
if ( nIdx[3] == 64 ) nIdx[3] = 0;
if ( nIdx[2] == 64 ) nIdx[2] = 0;
if ( nIdx[1] == 64 ) nIdx[1] = 0;
*(cpOutput+0) = (char)((nIdx[0]<<2) | (nIdx[1]>>4));
*(cpOutput+1) = (char)((nIdx[1]<<4) | (nIdx[2]>>2));
*(cpOutput+2) = (char)((nIdx[2]<<6) | nIdx[3]);
cpOutput += 3;
}
// set this to terminate output string
*cpOutput = '\0';
return;
}
void main () {
char sNonCoded[ 256 ];
char sEncoded[ 256 ];
strcpy( sNonCoded, "This is non-coded text" );
Base64Encode( sNonCoded, sEncoded );
printf( "Encoded: %s", sEncoded );
Base64Decode( sEncoded, sNonCoded );
printf( "Decoded back: %s", sNonCoded );
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!!, its working, thanks a lot for your help.
but how can i decode or encode a string?
but how can i decode or encode a string?
>>but how can i decode or encode a string?
You need to change the 'main()' function to do that for you, e.g.
void main () {
char sNonCoded[ 256 ];
char sEncoded[ 256 ];
printf("Please enter a string (256 bytes max)\n");
scanf( "%s", sNonCoded);
Base64Encode( sNonCoded, sEncoded );
printf( "Encoded: %s\n", sEncoded );
Base64Decode( sEncoded, sNonCoded );
printf( "Decoded back: %s\n", sNonCoded );
}
You need to change the 'main()' function to do that for you, e.g.
void main () {
char sNonCoded[ 256 ];
char sEncoded[ 256 ];
printf("Please enter a string (256 bytes max)\n");
scanf( "%s", sNonCoded);
Base64Encode( sNonCoded, sEncoded );
printf( "Encoded: %s\n", sEncoded );
Base64Decode( sEncoded, sNonCoded );
printf( "Decoded back: %s\n", sNonCoded );
}
ASKER
ty, great help.