| | |
Reading and editing characters in a string
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 29
Reputation:
Solved Threads: 0
I need to edit every character of a string for an assignment; apply a simple Caesar cipher on it. What is the C equivalent of "charAt()"? I remember my prof saying that all strings are terminated with a certain character in C and that you could run a while loop till that character, but I'm not sure how to do it.
0
#2 Nov 10th, 2009
C string is an array of characters. You may set or get a character at specific index.
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="ABC"; str[0]='a'; // replace 'A' with 'a'
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="Sample Text"; int i=0; while(str[i]!='\0') { /* put your code */ i++; }
Last edited by adatapost; Nov 10th, 2009 at 7:20 am.
•
•
Join Date: Oct 2009
Posts: 29
Reputation:
Solved Threads: 0
0
#3 Nov 10th, 2009
•
•
•
•
C string is an array of characters. You may set or get a character at specific index.
C Syntax (Toggle Plain Text)
char str[20]="ABC"; str[0]='a'; // replace 'A' with 'a'
C String (char array) is terminated with a '\0' (null) character.
C Syntax (Toggle Plain Text)
char str[20]="Sample Text"; int i=0; while(str[i]!='\0') { /* put your code */ i++; }
Thanks. I ended up doing something similar.
![]() |
Similar Threads
- Reading Characters from a String in C? (C)
- Capitalizing all characters of a string (C)
- Adding in escape characters into a string (C#)
- Count characters of a string. (C++)
- Counting all Non-blank Characters in a String (Java)
- Counting specific characters in a string (C)
- Removing characters from a string (C)
Other Threads in the C Forum
- Previous Thread: Link for OS Concepts code for C
- Next Thread: Reverse of number
Views: 260 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






