| | |
Algorithm for substitution encryption
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 80
Reputation:
Solved Threads: 1
Can someone explain to me what I'm doing wrong
OUTPUT:
fghijklmnopqrstuvwxyzabcde
Prints the whole enc array in order.
How do you print an individual character, not the entire array in C?
C Syntax (Toggle Plain Text)
#include <stdio.h> main(){ char ch = 'd'; char alp[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'}; char enc[26] = {'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e'}; for(int i = 0; i <= 26; i++){ if(ch = alp[i]){ printf("%c", enc[i]); } } return 0; }
fghijklmnopqrstuvwxyzabcde
Prints the whole enc array in order.
How do you print an individual character, not the entire array in C?
>for(int i = 0; i <= 26; i++){
I'd start with this. When you declare an array of 26, it means that the last valid index is 25. This loop runs off the end of the array.
>if(ch = alp[i]){
This is a common mistake too. The operator for equality is ==. The operator for assignment is =.
>How do you print an individual character, not the entire array in C?
Um, don't loop?
I'd start with this. When you declare an array of 26, it means that the last valid index is 25. This loop runs off the end of the array.
>if(ch = alp[i]){
This is a common mistake too. The operator for equality is ==. The operator for assignment is =.
>How do you print an individual character, not the entire array in C?
Um, don't loop?
I'm here to prove you wrong.
![]() |
Similar Threads
- Plzz help me out!!!! (C++)
Other Threads in the C Forum
- Previous Thread: strings
- Next Thread: How to measure C execution time
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string suggestions system test testing threads turboc unix urboc user whythiscodecausesegmentationfault win32api windowsapi






