We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,379 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

program to print the substring from substring by reading its first characte

#include <stdio.h>
#include <stdlib.h>
void main()
{
    int i,j,d=0,k;
    char a[30],b;
    printf("enter the string: ");
    fgets(a,sizeof(a),stdin);
    printf("enter the first character to be searched and printed: ");
    scanf("%c",b);
    for(i=0;a[i]!=32;i++)
    {
    if(b==a[i])
    {
        printf("%c",a[i]);
    }
    }


    for(i=0;a[i]!='\0';i++)
    {

       if(a[i]==32)
       {
           i++;
           k=i;
           if(b==a[i])
           {
               for(k=i;a[k]!==32;k++)
               {
                   printf("%c",a[k]);
               }
           }
       }
    }
}

error at line 29 and 36
output should be like this
enter the string: i love cricket
enter the chcarcter:c
output is cricket

2
Contributors
1
Reply
2 Hours
Discussion Span
9 Months Ago
Last Updated
2
Views
rithish
Posting Whiz in Training
268 posts since Apr 2011
Reputation Points: 23
Solved Threads: 9
Skill Endorsements: 0

error on 29 :
it is a[k]!=32. this is a relational operator that means not equal to. != and == is a operator to check the equality.

error at line 10:
it is address of a character which scanf expects. so use &b because b is just a character.

Secondly,

try to use the codeblocks. because I hope there is curly-bracket problem. in codeblocks , it automatically puts the completing bracket.

I_m_rude
Deleted Member

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0801 seconds using 2.67MB