• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

error LNK2019

hi experts,

im trying to compile this: http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20079662.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.
0
xapsx
Asked:
xapsx
  • 5
  • 4
1 Solution
 
jkrCommented:
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'
0
 
jkrCommented:
>>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?
0
 
xapsxAuthor Commented:
what u whant, i need a working  base64 decode & encode. thanks
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
novitiateCommented:
//code.cpp

int main()
{
    return 0;
}

Project->Settings->Link(Tab)->Project Options(ListBox)
chnage /subsystem:windows to /subsystem:console

_novi_
0
 
xapsxAuthor Commented:
i've gone to:

Configuration Propreties>Linker>System ->
      SubSystem = Console (/SUBSYSTEM:CONSOLE)

what is wrong?

thanks!
0
 
jkrCommented:
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 =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";


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 );
}
0
 
jkrCommented:
Sorry, that should have been

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static char* _cpBase64Encoding =
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";


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\n" );
Base64Encode( sNonCoded, sEncoded );
printf( "Encoded: %s\n", sEncoded );
Base64Decode( sEncoded, sNonCoded );
printf( "Decoded back: %s\n", sNonCoded );
}

That compiles and runs:

Encoded: VGhpcyBpcyBub24tY29kZWQgdGV4dAo=
Decoded back: This is non-coded text
0
 
xapsxAuthor Commented:
thanks!!, its working, thanks a lot for your help.

but how can i decode or encode a string?
0
 
jkrCommented:
>>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 );
}

0
 
xapsxAuthor Commented:
ty, great help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now