0

i ma using visual c++ for my dictionary project ..... but visual c++ hangs on compilation ....while this same code runs well on Linux mint.... i am using visual studio for that i want to give my code GUI form.... here's my code

///////////////////////////////////////////
#include<stdio.h> 
int upper[30],lower[30],indno=0,row=0,col=-1;

char *p[]={"a",
"एक, अंग्रेजी वर्णमाला का प्रथम अक्षर तथा स्वर,( तर्क मे) पहला कल्पित पुरुष वा प्रस्ताव",
"aback",
"अचानक, एकाएक,पीछे",
"abandon",
"छोड देना, त्याग देना, त्यागना, तजना,बिना आज्ञा नौकरी छोडना, अपने को( दुराचार आदि में) छोड देना, दे देना",
"abandoned",
"छोडा हुआ, निर्जन( स्थान) ,बिगडा हुआ, इन्द्रिय लोलुप, लम्पट, दुराचारी, आवारा",
"abandonment",
"पूर्ण त्याग, सम्पूर्ण आत्मोत्सर्ग, बिल्कुल छोड देना",
//.
//.
//.
//. ///////////////remaining 15000 words and meaning
//.
//.
//. 
};

void main()
{

 }
rishi
  • 653
  • 7
  • 10
  • 2
    I would suggest retry after changing `wchar_t *p[]={L"a", L"एक, अंग्रेजी वर्णमाला का प्रथम अक्षर तथा स्वर,( तर्क मे) पहला कल्पित पुरुष वा प्रस्ताव",`... i.e. char -> whcar_t and `L` prepended to strings and I am sure you would need more changes. Also change file format to unicode (there is an option in file menu). Not related but main should return int. – Mohit Jain Jul 31 '14 at 07:38
  • it should be [`int main(void)`](http://stackoverflow.com/questions/449851/why-do-we-need-to-use-int-main-and-not-void-main-in-c), not `void main()` http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c – phuclv Jul 31 '14 at 08:28
  • What's your source file encoding? And does MSVC really hang (or is it the resulting executable)? – mafso Jul 31 '14 at 09:42
  • @LưuVĩnhPhúc That's both irrelevant and incorrect in both C++ and MicroSoft C (according to your own link). – ams Jul 31 '14 at 10:13
  • @ams did you read the link carefully? I do know that Turbo C and MSVC accepts `void main` and I once always use it but C and C++ standard require the correct main signature to return int. Of course I know it doesn't answer the question so I added it as a comment – phuclv Jul 31 '14 at 10:17
  • @LưuVĩnhPhúc Yes, `void main()` is technically wrong, but your replacement is only correct in one of the three languages mentioned in the question, and is more wrong in the other two that the original. Not helpful. – ams Jul 31 '14 at 10:23
  • @ams I don't know what you mean. What's not correct about that? – phuclv Jul 31 '14 at 11:16
  • @mohit jain ..........solved thank you – rishi Aug 01 '14 at 07:31
  • does not work with this.....strlen(p[i])...visual says .... 1 IntelliSense: argument of type "wchar_t *" is incompatible with parameter of type "const char * – rishi Aug 01 '14 at 07:35
  • You need to use [wcslen](http://msdn.microsoft.com/en-us/library/78zh94ax.aspx). This is what I meant by more changes. – Mohit Jain Aug 01 '14 at 07:59
  • programming is a huge subject ...... how can i print this p[1] or any string to textbox1 in visual c++ .....private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { textbox1->Text=p[1]; //cannot convert wchar to system::string //i googled but not exactly found the answer – rishi Aug 02 '14 at 08:23
  • textbox1->Text=(gcnew String(p[1])); ...it worked – rishi Aug 02 '14 at 08:40

1 Answers1

1

Collecting from my comments (as confirmed by the OP): You are using hindi strings in your program which may not be supported by your current encoding. You can convert all char strings to wide char strings (unicode) by prepending an L to strings and change the type of strings from char * to wchar_t *.

If this change works for you, you would need more changes like:

strlen -> wcslen
%s -> %ls (in print)
printf -> wprintf (Optional)

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

wchar_t *p[]={L"a",
              L"एक, अंग्रेजी वर्णमाला का प्रथम अक्षर तथा स्वर,( तर्क मे) पहला कल्पित पुरुष वा प्रस्ताव",
              L"aback",
              L"अचानक, एकाएक,पीछे",
};

int main()
{
  setlocale(LC_CTYPE, "en_IN");
  wprintf(L"%ls -> %ls\n", p[0], p[1]);
  wprintf(L"%ls -> %ls\n", p[2], p[3]);
  return 0;
}
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100