Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why can't I print Len?, Segmentation Fault

0 votes
asked Apr 26, 2018 by SavageMango (310 points)
#include <iostream>
#include <string>

using namespace std;

   int main()
   {
    int Len;
    Len=0;
    int size;
    char Word;
    char arr[size] = {Word};
    cout<<"Enter the size of your array"<<endl;
    cin>>size;
    cout<<"Please enter your string"<<endl;
    cin>>Word;
    for(int i=0; i<size; i++)
    {
        Len+=1;
        for(int x=1;x<size;x++)
        {
            if (i>=x)
            {
                if(arr[i]=arr[i-x])
                {
                    Len-=1;
                }
                else
                    continue;
            }
            else
               break;
        }
    }
    cout<<Len<<endl;
}

1 Answer

0 votes
answered Jan 22, 2019 by Jyo

Hi,

At first you have to initialize the variable size, later you have to assign value to char array arr.

Else system wont be knowing the size of Char array.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...