c# - My code is not giving the desired output -


my text file has following information

   names                     date of birth        date of joining       bella swan                01/18/1986           12/12/2012    edward cullen             10/13/1983           05/08/2013    jacob black               10/18/1981           12/12/2012    carlisle cullen           05/08/1953           12/16/1998    alice cullen              01/18/1986           09/09/2009 

if user enters date, records relevant date should pulled up. user enters date 01/18/1986 display shows following details:

      bella swan                01/18/1986           12/12/2012       alice cullen              01/18/1986           09/09/2009 

if user enters date 12/12/2012

       bella swan                01/18/1986           12/12/2012        jacob black               10/18/1981           12/12/2012 

the guidelines need abide not work jagged arrays, linq, list, exception, etc.

i don't know how above output. tried didn't work.

static void main() {     console.writeline("enter date");     string date = console.readline();     string line = null;     filestream fs = new filestream("scheduler.txt", filemode.open,fileaccess.read);     streamreader reader = new streamreader(fs);     {         while ((line = reader.readline()) != null)         {             if (line.contains(date))             {                    console.writeline(date);                 break; // stop             }         }     } }   

why doing this?

console.writeline(date); 

you need print whole line:

console.writeline(line); 

why doing this?

break; // stop 

you're stopping prematurely before you've read whole file; remove continue looping until reach end of file.

other possible problem: did check make sure input valid date? 1 way this:

datetime valid;  if(!datetime.tryparse(date, "mm/dd/yyyy", cultureinfo.invariantculture)) {     // handle invalid date format } 

beyond that, pretty start. you're on right approach.

however, question terribly posed. next time, state actual, concrete problem you're having. might find articulating issue understand own code better can find mistakes yourself. example, if had said:

i have code, it's printing date user input , stopping....

you might have looked @ code , wondered why case. , might have noticed have console.writeline(date) , gone ha! , maybe, maybe, same break.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -