Thread: not getting required result

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    26

    Talking not getting required result

    Code:
    void search(){void output(void);
    char title[20],;
    char *p;
    clrscr();
    
    
    i=0;
    char *t;
    clrscr();
    printf("Report Title for Search:");
    fflush(stdin);
    scanf("%[^\n]",&p);
    
    
    do{
    t=strstr(list[i].title,p);
    if(t!=NULL)
    output();
    i++;
    }
    while(i<10);
    Info:Program that stores information about reports .the above function searches the report according to its title. list is the name of the structure that stores the records.

    why i'm using strstr:
    for eg. there is a report titled 'report on tigers'

    i want the report information to be output if someone searches for 'tiger'

    Output:displays all the entries i have made till now

    file is attached.please reply soon and thanks in advance
    Attached Files Attached Files

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Your code was short enough to be posted here in [code][/code] bbcode tags instead of attaching it as a file.

    There are a few things that you need to do immediately:
    • Change the source file extension from ".CPP" to ".c". If you use a C-only compiler or the correct compiler options, this might not matter, but you probably aren't, hence you are probably compiling your C code as C++ instead of C.
    • Indent your code properly. You should also format your code such that function definitions have at least one blank line in between.
    • Get rid of the dependency on <conio.h>. You most likely don't need it. This also means getting rid of the non-standard functions like clrscr and getch.
    • void main should be int main
    • Get rid of fflush(stdin) as it results in undefined behaviour.
    • Get rid of your use of goto, most likely by using a loop. You are not qualified to use goto.

    When you are done with these changes, post the updated code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    26
    problem got solved when i removed the pointers anyways thnks

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    24
    Quote Originally Posted by laserlight View Post

    • Get rid of your use of goto, most likely by using a loop. You are not qualified to use goto.
    I can't stop laughing, reminds me of me... Not you but the other person I was in so deep once I couldn't see a way out I looked at goto and thought for a second it was the only way. As I looked left and then right in my empty room I clicked delete file.

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    26
    sometimes knowing less helps lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I test for a result, but any result over 1 fails
    By jeremy duncan in forum C++ Programming
    Replies: 10
    Last Post: 05-23-2012, 01:23 PM
  2. No result out for this CP
    By leevenchoon in forum C Programming
    Replies: 12
    Last Post: 07-10-2011, 11:36 AM
  3. What would be the result...
    By sreeramu in forum C Programming
    Replies: 8
    Last Post: 03-25-2008, 04:43 AM
  4. No Result when run *.exe
    By hednast in forum C Programming
    Replies: 6
    Last Post: 08-23-2005, 12:50 AM
  5. rand() result required float!!!!
    By goosematt in forum C Programming
    Replies: 1
    Last Post: 02-29-2004, 03:59 PM