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: shakunni is an unknown quantity at this point 
Solved Threads: 0
shakunni shakunni is offline Offline
Light Poster

Reading and editing characters in a string

 
0
  #1
Nov 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 501
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #2
Nov 10th, 2009
C string is an array of characters. You may set or get a character at specific index.
  1. char str[20]="ABC";
  2. str[0]='a'; // replace 'A' with 'a'

C String (char array) is terminated with a '\0' (null) character.
  1. char str[20]="Sample Text";
  2. int i=0;
  3. while(str[i]!='\0') {
  4. /* put your code */
  5. i++;
  6. }
Last edited by adatapost; Nov 10th, 2009 at 7:20 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 29
Reputation: shakunni is an unknown quantity at this point 
Solved Threads: 0
shakunni shakunni is offline Offline
Light Poster
 
0
  #3
Nov 10th, 2009
Originally Posted by adatapost View Post
C string is an array of characters. You may set or get a character at specific index.
  1. char str[20]="ABC";
  2. str[0]='a'; // replace 'A' with 'a'

C String (char array) is terminated with a '\0' (null) character.
  1. char str[20]="Sample Text";
  2. int i=0;
  3. while(str[i]!='\0') {
  4. /* put your code */
  5. i++;
  6. }

Thanks. I ended up doing something similar.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 260 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC