|
|
back to boardwhy compilation error in 1002 Posted by Cooler 8 Feb 2003 21:12 Sorry I'm beginner What compilator do U use? my programm compilated on my compilator? but your tester say "Compilation error" My progs (1002): #include <iostream.h> #include <string.h> const char code[10][3] = { "oqz", "ijj", "abc", "def", "ghh", "kll", "mnn",
"prs", "tuv", "wxy" }; char num[110]; struct elem { int lstr; char str[51]; }; elem a[101]; int n; long nvoc; int lvoc; char voc[51]; int nwords(int pos) { int n=0; while (a[pos].lstr) { n++; pos-=a[pos].lstr; } return n; } int incode(char a, int n) { return (code[n][0]==a) || (code[n][1]==a) || (code[n][2]==a); } int possib(int st, int l, char * s) { int i; for (i=st; i<st+l; i++) if (!incode(s[i-st],num[i]-48)) return 0; return 1; } int pos[100]; int lpos; int main() { int cur; int i; while (1) { cin >> num; if (num[0]=='-') break; // init n=strlen(num); for (i=0; i<=n; i++) a[i].lstr=0; cin >> nvoc; while (nvoc--) { cin >> voc; lvoc=strlen(voc); for (i=0; i<=n-lvoc; i++) { if ((i==0 || a[i].lstr)&&((nwords(i)+1<nwords (i+lvoc))||(a[i+lvoc].lstr==0))&& possib(i,lvoc,voc)) { a[i+lvoc].lstr=lvoc; strcpy(a[i+lvoc].str,voc); break; } } } // while(nvoc--) if (a[n].lstr) { lpos=0; cur=n; while(cur) { pos[lpos]=cur; lpos++; cur-=a[cur].lstr; } for (i=lpos-1; i>=0; i--) cout << a[pos[i]].str << " "; cout << endl; } else cout << "No solution.\n" ; } // while (1) return 0; } Re: why compilation error in 1002 Posted by HelL 10 Feb 2003 14:21 > const char code[10][3] = > { "oqz", "ijj", "abc", "def", "ghh", "kll", "mnn", > > "prs", "tuv", "wxy" }; array bounds overflow, says my compilator. Help from MSDN: "Too many initializers were present for the given array. Make sure that the array elements and initializers match in size and quantity. This error can be caused by not leaving space for the null terminator in a string. The following is an example of this error: char abc[4] = "abcd"; // error, array contains 5 members" So, imho, try to write char code[10][4] :)) |
|
|