concept of char array
please give me feedback on :)
concept of character arrays in c++
#include "iostream"
#include "stddef.h"
#include <math.h>
using namespace std;
int main( )
{
const int n = 100;
char array[n] ;
cout<<"Enter the string:"<<endl;
cin.getline(array,100, '\n');
int length = 0;
length = strlen(array);
char A[n];
cout<<A<<endl;
strcpy(A, array);
cout<<"After coping:"<<A<<endl;
strcpy(A,"Hello---");
cout<<A<<endl;
strcat(A, array);
cout<<A<<endl<<"length:"<<strlen(A)<<endl;
strcpy(A,"123");
int number = atoi(A);
cout<<++number<<endl;
cout <<"A(123) is smaller than array(" << array << ") : "<<strcmp(A,array)<<endl;
cout <<"array(" << array << ") is greater than A(123) : "<<strcmp(array,A)<<endl;
cout <<"Equal : "<<strcmp("ICS","ICS")<<endl;
cout <<"UnEqual ICS is smaller than ICS1: "<<strcmp("ICS","ICS1")<<endl;
cout <<"UnEqual ICS1 is smaller than ICS2: "<<strcmp("ICS1","ICS2")<<endl;
return 0;
}
concept of character arrays in c++
#include "iostream"
#include "stddef.h"
#include <math.h>
using namespace std;
int main( )
{
const int n = 100;
char array[n] ;
cout<<"Enter the string:"<<endl;
cin.getline(array,100, '\n');
int length = 0;
length = strlen(array);
char A[n];
cout<<A<<endl;
strcpy(A, array);
cout<<"After coping:"<<A<<endl;
strcpy(A,"Hello---");
cout<<A<<endl;
strcat(A, array);
cout<<A<<endl<<"length:"<<strlen(A)<<endl;
strcpy(A,"123");
int number = atoi(A);
cout<<++number<<endl;
cout <<"A(123) is smaller than array(" << array << ") : "<<strcmp(A,array)<<endl;
cout <<"array(" << array << ") is greater than A(123) : "<<strcmp(array,A)<<endl;
cout <<"Equal : "<<strcmp("ICS","ICS")<<endl;
cout <<"UnEqual ICS is smaller than ICS1: "<<strcmp("ICS","ICS1")<<endl;
cout <<"UnEqual ICS1 is smaller than ICS2: "<<strcmp("ICS1","ICS2")<<endl;
return 0;
}
Comments
Post a Comment