I have been coding for a little bit in VB mostly and decided to try C right all is dandy until I try using a function

I am getting a conflicting types error in function encrypt

here is my beautiful code

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
  /* Declaring the functions */
  char encrpyt(int , char);
  
  int key = 5;
  char string[81];
  
  gets(string);
  
  encrypt(key , string);
  
  system("PAUSE");	
  return 0;
}


char encrypt(int codekey, char stringydoo[80] ) /* Encrypt Header line */
{
      int i,stringnums[80];
      
      for(i=0; i<80; i++)
      {
           stringnums[i] = stringydoo[i];
           if (stringnums[i]>=32 && stringnums[i]<=126)
           {
                               
                               stringnums[i] = stringnums[i]+ codekey;
                                                  
                                                  if (stringnums[i]>=126)
                                                  {
                                                                           stringnums[i] = 32 + (stringnums[i]%126);
                                                  }
                                                                           
           stringydoo[i] = stringnums[i];
           }
           
  
      }

      
      puts(stringydoo);
      system("PAUSE");
}

this is the exact errors from bloodshed

21 xxxx\main.c conflicting types for 'encrypt'
13 xxxx\main.c previous implicit declaration of 'encrypt' was here

Recommended Answers

All 9 Replies

I have been trying things for about 3-hours I think I have tried everything :/

check line #6:

char encrpyt(int , char);

the parameters are int and char.
In line #20

char encrypt(int codekey, char stringydoo[80] ) /* Encrypt Header line */

now the params are one int and a char [].

correct the prototype at line #6.

check line #6:

char encrpyt(int , char);

the parameters are int and char.
In line #20

char encrypt(int codekey, char stringydoo[80] ) /* Encrypt Header line */

now the params are one int and a char [].

correct the prototype at line #6.

I changed

char encrpyt(int , char);

to

char encrpyt(int , char[80]);

to match the version on the function header both ways

when I removed all mention of an array from the main function I still got the error so I changed the code like so

{
  /* Declaring the functions */
  void encrpyt(int , char);
  
  int key = 5;
  char string;
  
  
  encrypt(key , string);
  
  system("PAUSE");	
  return 0;
}


void encrypt(int codekey, char stringydoo) /* Encrypt Header line */

and I still have the error

try making your declaration before main (not inside main)

Same thing. right now the prototype is

void encrpyt(int , char []);

string is defined like

char string[81]

the pass is

encrypt(key , string);

The function header is

void encrypt(int codekey, char spots[])

hi there is already one library method in unistd.h called encrypt() hence it is giving the problem.
Change the function name to something else like encryptit().
It should work.

commented: Thank you +1

still nothing

still nothing

hi, i tried the following program in my pc and it compiled successfully.

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

int main(int argc, char *argv[])
{

  char encryptit(int x, char c[80]);

  int key = 5;
  char string[81];

  gets(string);

  encryptit(key , string);

  system("PAUSE");
  return 0;
}

char encryptit(int codekey, char stringydoo[80] ) /* Encrypt Header line */
{
      int i,stringnums[80];

      for(i=0; i<80; i++)
      {
           stringnums[i] = stringydoo[i];
           if (stringnums[i]>=32 && stringnums[i]<=126)
           {

                               stringnums[i] = stringnums[i]+ codekey;

                                                  if (stringnums[i]>=126)
                                                  {
                                                                           stringnums[i] = 32 + (stringnums[i]%126);
                                                  }

           stringydoo[i] = stringnums[i];
           }


      }


      puts(stringydoo);
      system("PAUSE");
}

hi, i tried the following program in my pc and it compiled successfully.

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

int main(int argc, char *argv[])
{

  char encryptit(int x, char c[80]);

  int key = 5;
  char string[81];

  gets(string);

  encryptit(key , string);

  system("PAUSE");
  return 0;
}

char encryptit(int codekey, char stringydoo[80] ) /* Encrypt Header line */
{
      int i,stringnums[80];

      for(i=0; i<80; i++)
      {
           stringnums[i] = stringydoo[i];
           if (stringnums[i]>=32 && stringnums[i]<=126)
           {

                               stringnums[i] = stringnums[i]+ codekey;

                                                  if (stringnums[i]>=126)
                                                  {
                                                                           stringnums[i] = 32 + (stringnums[i]%126);
                                                  }

           stringydoo[i] = stringnums[i];
           }


      }


      puts(stringydoo);
      system("PAUSE");
}

Thank you very much for helping me, I see what I was doing wrong when I compared the two now. :/ Thank you for the spoon feed. I now have a new goal. To keep at it until I get it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.