Hunspell returns bool instead words - hunspell

help please with Hunspell problem, can\t make this stuff works well.
Here is my code, it returns bool value TRUE unstead the suggestion of word.
int main(array<System::String ^> ^args)
{
char *aff = "c:\\en_US.aff";
char *dic = "c:\\en_US.dic";
Hunspell *spellObj = new Hunspell(aff,dic);
const char *named = "hello";
int result = spellObj->spell(named);
char ** wlst;
char ** wlst2;
int ns = spellObj->suggest(&wlst,named);
int abc = spellObj->analyze(&wlst2,named);
Console::WriteLine(ns);
for (int i = 0; i<ns; i++)
{
Console::WriteLine(&wlst[i]);
}
spellObj->free_list(&wlst,ns);
delete spellObj;
Console::WriteLine(result);
getchar();
return 0;
How can i make this suggestion works?

must use std::cout instead Console::WriteLine (facepalm)

Related

How to return a pointer string from C Function

Someone pleae help me out with my this code... It prints (Null)
Please someone do also explain with an answer...
#include<stdio.h>
#include<string.h>
char *findStringReverse(char *);
int main(){
char str[50];
printf("Enter a String\n");
scanf("%s", str);
if( strlen(str) > 10 )
{
printf("Invalid String.");
return 0;
}
printf("Reverse of the String: %s\n",findStringReverse(str));
}
char *findStringReverse(char *str){
int i,len;
char rev[10];
len = strlen(str);
for(i=0;i<=len;i++)
rev[i] = str[len-i-1];
printf("%s\n",rev); // Here it prints the reverse of the string.
return rev; // But unable to return.
}
So I am getting my output for the reverse string in the rev variable which is in the function below of the main code but I am unable to return the string stored in rev how can I do it ? In the main function when I print the value it shows (NULL).
The constraint given with the problem is that the rev value must be returned with char * way only.
Any help would be appreciated... ^_^

best way to store data from mysql result using C

My C programming is decidedly rusty:-(
I have studied http://zetcode.com/db/mysqlc/ and essentially comfortable with it.
But I am unsure of the best way of storing the data retrieved.
int num_fields = mysql_num_fields(result);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result))) {
for(int i = 0; i < num_fields; ) {
printf("%s ", row[i] ? row[i] : "NULL");
}
printf("\n");
this works fine and give me exactly the correct results.
Being familiar with perl hashes, I am tempted to use a C structure. Each record in my (small) database consists of different types of columns: char, float, int etc.
So I have:
struct Parameter {
char name[LEN_NAME];
float max;
float min;
float sample_interval;
int active;
char units[LEN_UNITS];
char start[LEN_START];
char start_time[LEN_START_TIME];
char end[LEN_END];
char end_time[LEN_END_TIME];
char type[LEN_TYPE];
};
struct Parameter parameters[MAX_PARAMETERS];
Where the LENs are defined constants.
I am trying things like:
num_fields = mysql_num_fields(result);
int r = 0;
while ((row = mysql_fetch_row(result))) {
for(int i = 0; i < num_fields; i++) {
printf("%s ", row[i] ? row[i] : "NULL");
sscanf(row[0], "%LEN_NAMEs", parameters[r].name);
sscanf(row[1], "%d", &parameters[r].max);
Which seems to be working OK for the chars, but not for the other types.
Struggling. Perhaps I am up a gum tree!

How to reverse a structure in text file with C?

I have an exercise and I don't know how to solve it well!
I want write a C program that give from user the information of a student and then save it to file A.txt. After that reverse the first name, last name and student number and save it to file B.txt.
For example:
john
lopez
123456
It changes to:
nhoj
zepol
654321
#include <stdio.h>
#include <stdlib.h>
#define SIZE 50
struct student {
char fname[SIZE];
char lname[SIZE];
char num[SIZE];
}st;
int main()
{
FILE *in, *out;
char ch;
int tmp=0,flag=0,i;
printf("INPUT First name: ");
scanf("%s", &st.fname);
printf("INPUT Last name: ");
scanf("%s", &st.lname);
printf("INPUT personal num: ");
scanf("%s", &st.num);
in= fopen("A.txt", "w");
fputs(st.fname, in);
fputs(st.lname, in);
fputs(st.num, in);
fclose(in);
in= fopen("A.txt", "r");
out=fopen("B.txt", "w");
fgets(st.fname, strlen(st.fname)+1,in);
strrev(st.fname);
fputs(st.fname, out);
printf("\n%s", st.fname);
fgets(st.lname, strlen(st.lname)+1, in);
strrev(st.lname);
fputs(st.lname, out);
printf("\n%s", st.lname);
fgets(st.num, strlen(st.num)+1, in);
strrev(&st.num);
fputs(st.num, out);
printf("\n%d", st.num);
fclose(in);
fclose(out);
return 0;
}
If you want to copy the data to a file, then you first need to put the data in some dynamic memory allocation and then after reversing the content required in dynamic memory, you need to copy it into your file.
this is the program to reverse the each word in given string
#include
#include
void reverse_string(char*);
void reverse_words(char*);
int main() {
char a[100];
gets(a);
reverse_words(a);
printf("%s\n", a);
return 0;
}
void reverse_words(char *s) {
char b[100], *t, *z;
int c = 0;
t = s;
while(*t) { //processing complete string
while(*t != ' ' && *t != '\0') { //extracting word from string
b[c] = *t;
t++;
c++;
}
b[c] = '\0';
c = 0;
reverse_string(b); // reverse the extracted word
z = b;
while (*z) { //copying the reversed word into original string
*s = *z;
z++;
s++;
}
while (*s == ' ') { // skipping space(s)
s++;
}
/*
* You may use if statement in place of while loop if
* you are assuming only one space between words. If condition is
* used because null terminator can also occur after a word, in
* that case we don't want to increment pointer.
* if (*s == ' ') {
* s++;
* }
*/
t = s; // pointing to next word
}
}
/*
* Function to reverse a word.
*/
void reverse_string(char *t) {
int l, c;
char *e, s;
l = strlen(t);
e = t + l - 1;
for (c = 0; c < l/2; c++) {
s = *t;
*t = *e;
*e = s;
t++;
e--;
}
}
Then you can try using fputc, i.e., reading char by char along with a loop to get your data line by line as 3 lines.
char *ch;
for(i=0;st.fname[i];i++)
{
ch=getc(st.fname[i]);
fputc(ch,in);
}
repeat the same even for st.lname and st.num

G++ no matching constructor for initialization

I have the following classes in a .h:
class Register {
int content;
public:
Register ();
}reg;
class Simulator {
int op1, op2, initial_pos;
Register RA, RB, RC, RD, PC, SP, FP;
bool zero, neg;
int mem[1024];
public:
Simulator (int, int, const std::string);
void Memdump ();
void Exec_next ();
}sim;
and the definition for the simulator constructor is as follows:
Simulator::Simulator (int i, int j, int k, std::string fname) {
FILE* instructions;
valA = 0;
valB = 0;
valC = 0;
valP = 0;
valE = 0;
op1 = 0;
op2 = 0;
zero = false;
neg = false;
valid1 = false;
valid2 = false;
PC::content = 0;
FP::content = j;
SP::content = j;
initial_pos = k;
for (int i = 0; i < 1024; i++)
mem[i] = 0;
//Read input file
if (instructions = fopen (filename, 'r') == NULL) {
cout << "Error 404: file not found\n";
exit (404);
}
for (int i = 0; !feof (instructions); i++)
fscanf (instructions, "%d\n", &(mem[i + initial_pos]) );
fclose (instructions);
}
but when i try to compile this code i get the following error message:
./TP1.h:45:2: error: no matching constructor for initialization of
'class Simulator'
}sim;
^
./TP1.h:42:3: note: candidate constructor not viable: requires 3
arguments, but 0 were provided
Simulator (int, int, const std::string);
^
./TP1.h:10:7: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument, but 0 were provided
why isn't g++ finding the constructor?
Nevermind. I'm using 1 less argument than required.

How to save an array of unsigned char to MySQL

Any idea on how to save an array of unsigned char to a field in MySQL database ? I'm considering BLOB, but how can I convert it to QByteArray and convert it back to an array of unsigned char when I want to ? BTW, I'm trying to save fingerprint data.
I managed to solve this using the codes below (copied directly from my project)
struct fp {
unsigned char Template[MAX_TEMPLATE_SIZE];
int size;
};
// unsigned char to QByteArray
QByteArray FingerPrint::charArrayToByteArray(fp fp0) {
QByteArray ba;
for (int i=0; i
// QByteArray to unsigned char
fp FingerPrint::byteToFp(QByteArray *ba) {
fp fp0;
for (int i=0; isize(); i++) {
fp0.Template[i] = ba->at(i);
}
fp0.size = ba->size();
return fp0;
}