BrainDump
  Home arrow BrainDump arrow Page 3 - C: Strings
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

C: Strings
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-03-03

    Table of Contents:
  • C: Strings
  • Storing Strings
  • String Operations
  • Strcat()
  • Strcmp()
  • Strcpy()

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    C: Strings - String Operations
    (Page 3 of 6 )

    There are many string functions in C, and we will discuss a few of them here, starting with the strlen() function. Before we do though, be sure to include the <string.h> library.

    Strlen()

    If you want to count the amount of characters in a string, you can use the strlen() function.


    #include <stdio.h>

    #include <string.h>

    int main ()

    {

    char name[80];

    int length;

    printf("Enter your name: ");

    gets_s (name);

    length=strlen(name);

    printf("nThe name %s contains %d characters, including

    spaces.n",name, length);

    return(0);

    }

    This program creates an array capable of holding 79 characters called “name,” and a variable named length. It then prints some text asking the user to enter their name and stores the input in the name array. Next, we use the strlen() function to count the number of characters (including spaces) in the name array, and store it in the variable length. Finally, we print some text displaying the user's name and how many characters are in their name. If the user had input Aunt Jemima as their name, this would be the result:

      Enter your name: Aunt Jemima

      The name Aunt Jemima contains 11 characters, including spaces.

    More BrainDump Articles
    More By James Payne


       · Thanks for stopping by to read my article on C Strings. Here we discuss how to store...
     

    BRAINDUMP ARTICLES

    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC
    - VBScript: More Fun with the Date Functions
    - Vista Price Cuts Dissected




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway