Error while run

Write your question here.


Program Menu which will choose whether imported string will encode or will decode .Coding and decoding will be dealt with 2 functions.
Key encoding: The text used letters of the alphabet and numbers.Each letter string which is odd, it is being replaced by point two places after her in alphabet.Last letters Y, Z are replaced by A, B consequently .Even letters the sting does not suffer any changes. Odd numbers are replaced by the even numbers are their followers and steam are replaced by their odd precursor.Number 9 is coded to 0 and 0 to the ninth
The task to test two strings.First to encode and then encoded version to decode .Strings be placed in files and from there to take.






Here is code i have written, but it have some error. Anybody can help?
#include <stdio.h>
#include <ctype.h>
#include<iostream>
#include<string>
#include<fstream>
#define MAXVEL 100
using namespace std;
void kodiranje(char kod[])
{
int i=0;
while(kod)
{
if(i%2!=0)
{
if(isalpha(kod[i]))
if(kod[i]=='Y') kod[i]='A';
else
if (kod[i]=='Z') kod[i]='B';
else
kod=kod+2;
}
if(!isalpha(kod[i]))
{
if(kod[i]=='0') kod[i]='9';
else
if(kod[i]=='9') kod[i]='0';
else
{
if(kod[i]% 2!=0)
kod= kod ++;
else
kod[i]=kod[i]-1;
}
}
i++;
}
printf("%s",kod);
}

void dekodiranje(char kod[])//char kod[] == string kod
{
int i=0;
while(kod)
{
if(i%2!=0)
{
if(isalpha(kod[i]))
if(kod[i]=='A') kod[i]='y';
else
if (kod[i]=='B') kod[i]='z';
else
kod[i]=kod[i]-2;
}
if(!isalpha(kod[i]))
{
if(kod[i]=='0') kod[i]='9';
else
if(kod[i]=='9') kod[i]='0';
else
{
if(kod[i]%2!=0)
kod[i]=kod[i]+1;
else kod[i]=kod[i]-1;
}
}
i++;
}
printf("%s",kod);
}
int main()
{

char tekst[MAXVEL]; // string tekst
int izbor=-1;
printf ("Vnesi tekst \n");
scanf ("%s",tekst);
while (izbor!=0)
{
printf ("\n Pritisni 1 za kodiranje, 2 za dekodiranje,0 za izlez: \n");
scanf ("%d", &izbor);
switch (izbor)
{
case 1:
kodiranje(tekst);
break;
case 2:
dekodiranje(tekst);
break;
case 0:
break;
default:
printf ("Vnesovte pogresna opcija !\n");
}
}
ofstream out;
out.open("File1.txt");

out<<tekst;
out.close();
return 0;
}
while(kod)

Other than being null from the start, this loop will never end. Perhaps look for the null terminating character?

1
2
int i = 0;
while(kod[i] != 0)
God bless you! Thanks my friend, it works properly :)
Topic archived. No new replies allowed.