Note 2: String and File reading and writing
Note 2: String and File Reading and Writing
String:
A string is any group of characters enclosed in quotation marks, such as “computer science”. It is also character array with ‘\0’ at last element of array.
Example:
char str[17] = “computer science”;
same as
char str[17] = {‘c’, ‘o’, ’m’, ‘p’, ‘u’, ‘t’, ‘e’, ‘r’, ‘ ‘, ‘s’, ‘c’, ‘i’, ‘e’, ‘n’, ‘c’, ‘e’, ‘\0’};
Memory picture:
str
|c |o |m |
|strcat (ToS, FromS) |Concatenate string FromS onto the end of |ToS |
| |string ToS | |
|strcmp (s1, s2) |Compare lexically strings s1 and s2 |s1 < s2, negative integer |
| | |s1 = s2, 0 |
| | |s1 > s2, positive integer |
|strcpy (ToS, FromS) |Copy string FromS into string ToS |ToS |
|strlen (S) |Length of string S |Length of S |
String example:
In this example, read a whole number as string, and then pass as argument to a function that convert character numbers to the integer number; then stored in the integer variable and return it.
Source Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Header File
#include
#include
//Function Prototype
float convert(char []);
//Main Routine
int main(void)
{
char str[80], answer;
float num;
do
{
cout > str;
num = convert(str);
cout ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- csci 515 introduction to c programming spring 2000
- chapter 3 control statements
- umass boston computer science
- note 2 string and file reading and writing
- 3 purdue university
- string lab 2 input and output using strings
- edu
- data types and conversions in snobol4 excerpted from
- instructions on using strings in c
- homework 4 strings arrays and malloc
Related searches
- reading and writing games for 4th graders
- 2nd grade reading and writing worksheets free
- reading and writing statistics
- reading and writing worksheets
- 2nd grade reading and writing worksheet
- free reading and writing websites
- free reading and writing worksheets
- 4th grade reading and writing worksheets
- free reading and writing printable worksheets
- esl reading and writing practice
- reading and writing placement test
- reading and writing skills