Question data type mismatch

Status
Not open for further replies.

cfrank2000

Well-known member
Joined
Mar 6, 2021
Messages
71
Programming Experience
Beginner
I have code part with data type mismatch that stops the running program/source code.
character comparison:
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleApp2karater1
{
    class Program
    {
        class mystruct{
          public string kar;
          public int a;
        }
        static void Main(string[] args)
        {
            int[] a = new int[14];
            int i = 0;
            int j = 0;
            int k = -1;
            int hossz = 0;
            string[] tomb = new string[14];
            List<mystruct> tmb2 = new List<mystruct>();
            int[] tomb2 = new int[14];
            string str1 = "hello world!?/";
            string str2 = "";
            mystruct[] tmb = new mystruct[14];
          

            hossz = str1.Length;
            mystruct myrek = new mystruct();

            for (i = 0; i < hossz; i++)
            {
                for (j = 0; j < hossz; j++)
                {
                    if (str1[j] == str1[i])
                    {

                        a[j] = a[j] + 1;
                        if (a[j] < 2)
                        {
                            //k = k + 1;
                            tomb[i] = Convert.ToString(str1[i]);
                            tomb2[i] = 1;
                            k = k + tomb2[i];
                            
                            //tmb.kar[i]=str1[i];
                            //str2+=str1[i];
                        }
                        else
                        {
                            tomb[i] = "empty";
                        }



                    }

                }
                Console.Write(a[i] + " i " + i + " k " + k + " " + tomb[i] + " " + tomb2[i] + " \n");

            }

            k = 0;
            for (i = 0; i < hossz; i++)
            {
                tomb2[i] = tomb2[i] + 1;
                Console.Write(" a[" + i + " ] " + a[i] + " " + tomb[i]);
                Console.Write(" " + tomb2[i] + "\n");
                if (tomb[i] != "empty")
                {
                    mystruct mydata = new mystruct();
                    str2 += tomb[i];
                    mydata.kar +=tomb[i];
                    tmb2.Add(mydata);
                }

            }
            foreach (char ch in str2)
            {
                Console.WriteLine(" ch " + ch);
              

            }
            foreach (mystruct ch2 in tmb2)
            {
                Console.WriteLine(" tmb 1 " + ch2.kar);


            }
          
            /* */
            int i2 = 0;
            for (int dt=0;dt<hossz;dt++)
            {
                //foreach (mystruct dt2 in tmb2)
                for (int dt2 = 0; dt2 < hossz; dt2++)
                {
                    //i2++;
                    mystruct mydata = new mystruct();
                    string str = mydata.kar;
                    char character = str[0];
                    
                    if (character == str1[i2])
                    {                         
                        mydata.a += 1;
                        tmb2.Add(mydata);
                    }
                }

            }
            int i3 = -1;
            foreach (mystruct rek in tmb2)
            {
                i3++;
                
                    Console.WriteLine(i3 + " elem " + rek.kar + " db " + rek.a);
                
            }

        }
    }
}
 
We've told you in the past not to open duplicate threads about the same problem. I am too tired today to try to merge threads. I am closing this thread. Please reply to your old thread and tell us what progress you made it what new things you have tried to make progress.
 
Status
Not open for further replies.
Back
Top Bottom