|
Thanks for reply
I have change in code then runing well.Please check it.
#include "stdafx.h"
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char *s,*a;
int i,l,f,c,x;
printf("Enter a string : ");
scanf("%s",s);
l=strlen(s);
s[l]=0;
a=(char*)malloc(l);
for(i=0;i<l;i++);
f=1,c=0;
while(f)
{
x=l-1;
a[x]=c++;
for(i=0;i<l && c-1<l;i++)
printf("%c",s[a[x]]);
if(i>=l)
printf("\n");
while(a[x]>=l)
{
a[x]=c=0;
if(x<0){f=0;break;}
a[x]++;
}
}
printf("Completed");
return 0;
}
Error
Run-Time Check Failure #3 - The variable 's' is being used without being initialized.
Please help me
|
|
|
|
|
Here, i think you have to help yourself, by learning the syntax of C.
I prefer you to read a C programming book to get throught with syntax.
See in your code, you cannot use scanf as you wish, it is expecting the address of s. so your compiler is complaining
scanf("%s",s);
Expected code is
scanf("%s",&s);
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks for reply
Now i am getting exception in line s[l]=0;
Unhandled exception at 0x1026f8bc (msvcr90d.dll) in TestingProject.exe: 0xC0000005: Access violation reading location 0xcc006975.
|
|
|
|
|
try this
char *s = new char;
Failure is Success If we learn from it!!
|
|
|
|
|
I have change in code char *s = new char(230)
Still i have same exception.
Please help me
|
|
|
|
|
no, no, no .... That's not the way to go!
You put some code with some syntax error and even some misconception in it.
That reveal that you are not understanding what your code has to do.
The compiler just gives some errors, but those errors are random as your code is. Attempting to fix those errors doesn't lead anywhere: you're never granted your code will do what you expect.
For example:
char *s;
int i,l,*a,f,c,x;
printf("Enter a string : ");
scanf("%s",s);
s is a pointer pointing to nowhere: where do ypu thoing your scanf can write to ?!?
s[l]=0; tries to write to nowhere since s is nowhere
a is a pointer to int, but you do a=(char*)malloc(l) : what did you want to do? allocating char-s or int-s ?!
for(i=0;i
f=1,c=0;
while(f)
This is a mess of tokens with no syntax meaning! Raed about the for syntax, and understand the proper use of '()', ',', and ';'.
x=l-1 Wow... you're looking for problems: never use names like "O" and "l": I have to change font before find it's "l-1" and not "l-l" ... Do you get what I mean? If not, than that demonstrate the problem
Then: I see a malloc , but i don't see a free : not a good way to program...
I don't continue, but what can you do if you don't have clear in your mind what you're gonna do?
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Thanks for vital information and suggestion.
I want to generate Combination of given String.Like this CString test="ABC", then generate like this
AB
AC
AA
BB
BC
BA
CC
CA
CB
If you have any type solution or suggestion then please help me.
|
|
|
|
|
Ok, that's the problem. Now try to come to an algorithmic solution.
That doesn't need to be C or C++, just pseudocode.
Only when you find your algorithm looks meaningful, try to code it!
Than: the problem is not well formed. Do you want only two char-s combination? Does the input string needs to be 3 char-s wide or can it be whatever?
Be sure about that: you risk to produce a code that works on a very specific case, while looking for something more generic.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
yes you right.You have any idea about such type of algo because i havn't found algo.Please help me
|
|
|
|
|
no, I cannot do your homework.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
you don't do my home work just i want to know url link or forum name.i know why you do my home work.
thank
|
|
|
|
|
You can use casting, I know it's available in C++.
Don't know about C, does it have to be C or C++?
|
|
|
|
|
thank for make comment but sorry can you describe in detail.What's not available? please describe in detail.
|
|
|
|
|
i'm not sure if you've attempted to add float to an int data type, but you get compiler errors in the end.
you want to add float and int to each other.
Casting:
int x = 12;
float y = 4.0;
int sum = x + (int)y;
|
|
|
|
|
Thank for reply but it's not useful for me because where i use int + float.If you have solution then please help me.
|
|
|
|
|
Hi all,
i want to generate max. combination for any given value.
like for AB::
combinations are "AB";"BA";"AA";"BB"
i m using Permutation but it gives only 2 combination here.
so please help me for this.
thanks in advance.
|
|
|
|
|
Show your code.
Величие не Бога может быть недооценена.
|
|
|
|
|
int fac(int n)
{
if (n == 0) return 1;
else return n*fac(n - 1);
}
void permute(char *string, int n, int rank)
{
vector<char> vec;
for (int ctr = 0; ctr < n; ctr++) vec.push_back(string[ctr]);
for (int ctr = n; ctr >= 1; ctr--)
{
int quotient = rank/fac(ctr-1);
char c = vec[quotient];
vec.erase(vec.begin()+quotient);
*string++ = c;
rank%=fac(ctr-1);
}
}
void showpermutes(char *string)
{
char temp[20];
int n = strlen(string);
if (n > 19) return;
int nfac = fac(n);
for (int ctr = 0; ctr < nfac; ctr++)
{
strcpy(temp, string);
permute(temp, n, ctr);
cout << temp << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
showpermutes("AB");
system("PAUSE");
getche();
return 0;
}
|
|
|
|
|
|
its not display any combination.
|
|
|
|
|
You mean this article is not good?
but i felt this is what you are looking for.
Величие не Бога может быть недооценена.
|
|
|
|
|
No this is not my mean,
i mean to say that its diplay the number of combination instead of all diffrent combination.
i really need all cobination,not the number of combination.
as i already mention in my thread.
like for::
AB i want "AB";"BA";"AA";"BB";
if this code generate this type of combinations please tell me how can i do this.
thanks.
|
|
|
|
|
You may go recursive for that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi All
I am try to make number of possible key combination.I use google then i found number of example permutation and combination.There is common result in permutation and combination ignore repeated
Can any any help to permutation and combination ignore allowed?
Like CString test="AB";
out put->
AB
BA
AA
BB
Please help me
|
|
|
|
|
You may go recursive for that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|