0

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

Edited by Sapreaver: adding the error.

2
Contributors
9
Replies
10
Views
8 Years
Discussion Span
Last Post by Sapreaver
0

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

0

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.

0

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

0

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[])
1

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.

Votes + Comments
Thank you
0

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");
}
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.