why doesn't my code work?!

okay so im writing this code for an assignment where the program reads in a text file and then the user is asked to state the key they want to offset the text file to be encrypted by. this is my code so far and i am confused as to why an error keeps coming up.... anyones advice would be appriciated :D

/*A Program that will encrypt a text file using Ceaser Cipher*/
#include <stdlib.h>
#include <stdio.h>
void main()
{
/*Defines the stream*/
FILE *file_in;
FILE *file_out;
/*Maximum of 100 chaacters to be encrypted*/
char sentence[100];
/*File name being declared as a variable*/
char fname[50];
int key;
char cipher [26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
/*Asks user to enter name of file to encrypt*/
char *offset;
char *encrypt;

offset + cipher = encrypt;

printf ("Enter the file name that you would like to open\n");
/*Scans for the user to input name of file*/
scanf( "%s", fname);
/*Opens the text file the user has inputted*/
file_in = fopen(fname, "r");
/*Declaring */
int i=0;
/*While statement*/
while (!feof(file_in))
{
/*Reads the text file in character by character*/
fscanf(file_in, "%c", &sentence[i]);

i++;
}

sentence[i] = 0x00;
/*Prints each character of the text file individually*/
printf("%s\n", sentence);
/*Shows this message when end of file is reached*/
if (feof(file_in))
/*Message that is printed on screen to the user*/
printf("You have reached the end of the file\n");

//asking user for file name.
printf("please enter the file which you would like to write to and encrypt\n");

//scanning users input.
scanf( "%s", fname);

file_out = fopen(fname, "w");

printf("please enter the offset key");
scanf("%s", key);

if
(key >=1 && key <=25)
printf( "encryption will now begin");
else
printf("please enter a valid key");
scanf("%s", key);



printf("%s", offset);


//close the file
fclose(file_out);

//closes the open file.
fclose (file_in);
}
[code] Your code goes here [/code]
offset + cipher = encrypt; You can't add 2 char pointers, and you need a lvalue for assignment. What are you trying to do there?

1
2
int key;
scanf("%s", key);
Don't lie
Last edited on
ive changed a few things around now and it does work, thank you anyway.
dont lie? sorry im confused about that, what do you mean? im sorry im really new to c++ so i am still learning and making a lot of mistakes so really do appriciate feedback.

Lloyd.
Show the update code.
Please be more especific about the errors that you are getting.

scanf("%s", key); You are telling that you are going to read a string, but as a parameter you pass an integer.
scanf("%d", &key); Note that scanf ask for a memory address
Topic archived. No new replies allowed.