void input(char str[]){
gets(str);
}
void display(char str[]){
int i;
for(i=0;str[i]!='\0';i++)
printf("%c ",str[i]);
printf("\n");
}
int countA(char str[]){
int i,count=0;
for(i=0;str[i]!='\0';i++){
if(str[i]=='a'||str[i]=='A')
count++;
}
return count;
}
int findItem(char array[],int size,char item){
int i,found=0;
for(i=0;array[i]!='\0';i++){
if(array[i]==item){
found=1;
break;
}
}
return found;
}
int isPalindrome(char str1[]){
int i,size=strlen(str1)-1;
int yes=1;
for(i=0,j=size-1;i<=size/2;i++,j--){
if(str1[i]!=str1[j]){
yes=0;
break;
}
}
return yes;
}
int countVowel(char str[]){
int i,count=0;
for(i=0;str[i]!='\0';i++){
//val=toupper(str[i]);
//if(val=='A'||val=='E'||val=='I'||val=='O'||val=='U')
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'
||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')
count++;
}
return count;
}
MAIN CODE
#include<stdio.h>
#include"strings.h"
int main(void){
char string1[30]="hello world";
input(string1);
display(string1);
printf("%d\n",countA(string1));
return 0;
}
Showing posts with label C programming - Functions. Show all posts
void createArray(int la[], int n){
int i, d;
for (i=0;i<n;i++){
if(i<1)
scanf("%d", &la[i]);
else{
scanf("%d", &la[i]);
for(d=1;d<i+1;d++){
if(la[i]==la[i-d]){
printf("The number you entered is already in the list. Enter another no.: ");
i--;}}
}
}
}
void printArray(int la[],int n){
int i;
for (i=0;i<n;i++){
printf("%d ", la[i]);
}
}
int inserAtPos(int la[], int n, int item, int k){
int i, w,c;
for(i=1;i>0;i++){
if(contains(la,item,n)==1){
printf("The number you want to insert is already in the list. Enter another no.: ");
scanf("%d", &item);
}
else{
c=n;
for(w=k; w<(n+1); w++){
la[c]=la[c-1];
c--;
}
la[k-1]=item;
break;
}
}
return 1;
}
int contains(int la[], int item, int n){
int i, found=0;
for(i=0;i<n;i++){
if(la[i]==item){
found=1;
break;
}}
return found;
}
void insertFront(int la[], int n,int item ){
int i, w, c;
for(i=1;i>0;i++){
if(contains(la,item,n)==1){
printf("The number you want to insert is already in the list. Enter another no.: ");
scanf("%d", &item);
}
else{
c=n;
for(w=(n+1); w>1; w--){
la[c]=la[c-1];
c--;
}
la[0]=item;
break;
}
}
}
void removeAtPos(int la[], int n, int index){
int d, i;
i=index;
for(d=(i-1);d<n-1;d++){
la[index-1]=la[index];
index++;
}
}
int removeItem(int la[], int n, int item){
int d, c, f, remove=1;
if(contains(la,item,n)==0){
remove=-1;
}
else{
for(d=0;d<n;d++){
if(item==la[d]){
c=d;
for(f=(c);f<n-1;f++){
la[d]=la[d+1];
d++;
}
break;
}
}}
return remove;
}
int removeFront(int la[], int n){
int i;
for(i=0;i<n;i++){
la[i]=la[i+1];
}
return 1;
}
void locateIndex(int la[],int n, int item){
int d, i, g, f;
while(f=1){
for(i=0;i<n;i++){
if(item==la[i])
g=1;
f=2;
}
if(g==1){
for(d=0;d<n;d++){
if(item==la[d]){
printf("The item is at position %d.", d+1);
}
}
break;
}
else{
printf("Item is not in the list.");
printf("\nEnter another number: ");
scanf("%d", &item);
f=1;
}}
}
void sortAscending(int la[], int n){
int i, temp, b;
for(i=0;i<n;i++){
for(b=0;b<(n-(i+1));b++){
if (la[b]>la[b+1]){
temp=la[b];
la[b]=la[b+1];
la[b+1]=temp;
}}}
printf("Sorting successful!");
printf("\nARRAY list in ASCENDING order : ");
printArray(la, n);
}
void sortDescending(int la[],int n){
int i, temp, b;
for(i=0;i<n;i++){
for(b=0;b<(n-(i+1));b++){
if (la[b]<la[b+1]){
temp=la[b];
la[b]=la[b+1];
la[b+1]=temp;
}}}
printf("\nARRAY list in DESCENDING order : ");
printArray(la, n);
}
void locateItem(int la[],int n, int item){
int i;
for(i=0;i<n;i++){
if(item==la[i]){
printf("Its in the list!");
break;
}
else{
printf("Not in the list!");
break;
}
}
}
void box(){
printf("\n[A] Add");
printf("\n[B] Subtract");
printf("\n[C] Multiply");
printf("\n[D] Divide");
printf(" ");
printf("\nEnter what you want to execute: ");
}
void box2(){
printf("\n");
printf("\nC - reset values and input again");
printf("\nY - Continue and apply another operation to the answer");
printf("\nX - Exit");
printf("\nEnter you choice: ");
}
float add(float x,float y){
return x+y;
}
float sub(float x,float y){
return x-y;
}
float multi(float x,float y){
return x*y;
}
float dev(float x,float y){
return x/y;
}
void unionof(int result[], int *count, int set1[], int count1, int set2[], int count2){
int i=0, h=0;
for(i=0;i<count1;i++){
result[(*count)++]=set1[i];
}
for(h=0;h<count2;h++){
if(contains(count1, set1, count2, set2[h])==0){
result[(*count)++]=set2[h];
}}
}
int contains(int count1, int set1[], int count2, int set2[]){
int i, found=0;
for(i=0;i<count1;i++){
if(set1[i]==set2){
found=1;
break;
}
}
return found;
}
void display(int result[],int count){
int i;
printf("{");
for(i=0;i<count;i++)
printf("%d,",result[i]);
printf("\b}\n");
}
void toOctal(int num){
int i, temp, temp2, q, ar[100], count=0, h;
for (i=0;num>0;i++){
q=num;
num=num/8;
temp=num;
temp2=temp*8;
temp=q-temp2;
count++;
ar[i]=temp;
}
for(h=0;h<count;h++){
printf("%d", ar[count-1-h]);
}
}
int toDecimal(char *num){
int b, k, m, n;
int len, sum = 0;
len = strlen(num) - 1;
for(k = 0; k <= len; k++)
{
n = (num[k] - '0');
if ((n > 8) || (n < 0))
{
printf("\n\n ERROR! Octal has only 0 to 7!\n");
return (0);
}
for(b = 1, m = len; m > k; m--)
{
b *= 8;
}
sum = sum + n * b;
}
return(sum);
}
About this blog
These codes here are just based on my own knowledge learned from my IT subjects. I know there are more ways that this draft codes can be enhance, so..
Please feel free to comment & suggest.. Suggest Codes which makes my existing codes simpler.. Thanks!
Archives
Categories
- C programming - Functions (5)
- C programming - Main Source code (3)
Making Life Simple w/ Programming
Links
- w3schools.com
- Java & Textpad Setup Guide 2
- Java & Textpad Setup Guide
- ASCII Alphabet Characters
- File Handling - Forum
- File Handling - Tutorial 0.1
- File Handling - Tutorial 0.2
- Bin-Dec Conversion - Forum
- Use of getch(), getche(), & getchar()
- The C Book
- SEO
- Common C programming errors
- Tutorial - Array Functions
- August Council Tutorial - c
- C language tutorials
- cprogramminglanuage.net