-1

how to create a character array which will accept 8 characters from the user and than convert that array into string variable and if the user gives the more than 8 characters the program will throw an error. it's very difficult????

Votes + Comments
you are right he should show something b4 asking here
5
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by vinnitro
3

What have you done so far? We'll help with your homework, but not do it for you.

Votes + Comments
you are right he should show something b4 asking here
0
char[] ar = new char[8];

                Console.WriteLine("Enter The FileName(MAX 10 Alphabets");

               for (int i = 0; i<8; i++)
                    {
                        ar[i] = Convert.ToChar(Console.ReadLine());  
                    }
                    for (int j = 0; j<8; j++)
                    {
                     //how to convert array into string with help of loop.   
                    }
                    //missing the error statement
1
string output="";
for (int j = 0; j<8; j++)
{
//how to convert array into string with help of loop.
output += ar[j];
}
Console.WriteLine(output);

you can convert the character array into string like that...

On a second note, why are u taking a character array?? you can directly use a string variable. and then check if the value is more than 8 characters... and whatever u want

0
using System;
class Satvinder
{
    static void Main()
        {
            string name = Console.ReadLine();
            char[] naam;

            if(name.Length>8 || name.Length<=0)
            {
                Console.WriteLine("Please re-enter file name");
            }

            else 
            {
                naam = name.ToCharArray();

                for (int i = 0; i <8; i++)
                {
                    Console.WriteLine(naam[i]);
                }
            }
        }
}   
0

if you got the answer you have to mark it solved
Dont give any code plz first he have to show what he have done so far

Edited by vinnitro: missing something & clicked before writing everything

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.