I've been trying to make a program that takes as input a scramble word,
gets the anscii value of that scrambled word, and numerically sorts it. And tries to find the same numerical order in the word list.
Heres the code: -
#include <stdio.h>
-
#include <string.h>
-
//sort the anscci value numerically
-
void sort(int a[], int len) {
-
int j, i, t;
-
for(i=len-1; i>=0; i--) {
-
for(j=1; j<=i; j++) {
-
if(a[j-1] > a[j]) {
-
t = a[j-1];
-
a[j-1] = a[j];
-
a[j] = t;
-
}
-
}
-
}
-
}
-
//get the anscii value of the string.
-
void getanc(int a[], char b[]) {
-
int i;
-
for(i=0; i<strlen(b); i++) {
-
a[i] = (int)b[i];
-
}
-
}
-
-
main(int argc, char *argv[]) {
-
char file[1500][11], input[11];
-
int anc1[1500][11], anc2[11];
-
int i, j, x;
-
FILE *word = fopen("wordlist.txt", "r");
-
for(i=0; i<1480; i++) {
-
fgets(file[i], 11, word);
-
getanc(anc1[i], file[i]);
-
sort(anc1[i], strlen(file[i]));
-
}
-
strcpy(input, argv[1]);
-
getanc(anc2, input);
-
sort(anc2, strlen(input));
-
for(i=0; i<1480; i++) {
-
for(j=0; j<strlen(file[i]); j++) {
-
if(anc2[j] == anc1[i][j]) {
-
x++;
-
}
-
if(x == 10) {
-
printf("String is: %s", file[i]);
-
}
-
}
-
x=0;
-
}
-
}
-
All it does absolutley nothing. Does'nt print out anything, and I don't know why.
The word list is very big.
2 2324
I've been trying to make a program that takes as input a scramble word,
gets the anscii value of that scrambled word, and numerically sorts it. And tries to find the same numerical order in the word list.
Heres the code: -
#include <stdio.h>
-
#include <string.h>
-
//sort the anscci value numerically
-
void sort(int a[], int len) {
-
int j, i, t;
-
for(i=len-1; i>=0; i--) {
-
for(j=1; j<=i; j++) {
-
if(a[j-1] > a[j]) {
-
t = a[j-1];
-
a[j-1] = a[j];
-
a[j] = t;
-
}
-
}
-
}
-
}
-
//get the anscii value of the string.
-
void getanc(int a[], char b[]) {
-
int i;
-
for(i=0; i<strlen(b); i++) {
-
a[i] = (int)b[i];
-
}
-
}
-
-
main(int argc, char *argv[]) {
-
char file[1500][11], input[11];
-
int anc1[1500][11], anc2[11];
-
int i, j, x;
-
FILE *word = fopen("wordlist.txt", "r");
-
for(i=0; i<1480; i++) {
-
fgets(file[i], 11, word);
-
getanc(anc1[i], file[i]);
-
sort(anc1[i], strlen(file[i]));
-
}
-
strcpy(input, argv[1]);
-
getanc(anc2, input);
-
sort(anc2, strlen(input));
-
for(i=0; i<1480; i++) {
-
for(j=0; j<strlen(file[i]); j++) {
-
if(anc2[j] == anc1[i][j]) {
-
x++;
-
}
-
if(x == 10) {
-
printf("String is: %s", file[i]);
-
}
-
}
-
x=0;
-
}
-
}
-
All it does absolutley nothing. Does'nt print out anything, and I don't know why.
The word list is very big.
You never check if the file is opened correctlly. Try this: -
if (word != NULL)
-
{
-
printf("Could not open the file");
-
return 1;
-
}
-
else
-
{
-
... continue ...
-
}
-
I've been trying to make a program that takes as input a scramble word,
gets the anscii value of that scrambled word, and numerically sorts it. And tries to find the same numerical order in the word list.
Heres the code: -
#include <stdio.h>
-
#include <string.h>
-
//sort the anscci value numerically
-
void sort(int a[], int len) {
-
int j, i, t;
-
for(i=len-1; i>=0; i--) {
-
for(j=1; j<=i; j++) {
-
if(a[j-1] > a[j]) {
-
t = a[j-1];
-
a[j-1] = a[j];
-
a[j] = t;
-
}
-
}
-
}
-
}
-
//get the anscii value of the string.
-
void getanc(int a[], char b[]) {
-
int i;
-
for(i=0; i<strlen(b); i++) {
-
a[i] = (int)b[i];
-
}
-
}
-
-
main(int argc, char *argv[]) {
-
char file[1500][11], input[11];
-
int anc1[1500][11], anc2[11];
-
int i, j, x;
-
FILE *word = fopen("wordlist.txt", "r");
-
for(i=0; i<1480; i++) {
-
fgets(file[i], 11, word);
-
getanc(anc1[i], file[i]);
-
sort(anc1[i], strlen(file[i]));
-
}
-
strcpy(input, argv[1]);
-
getanc(anc2, input);
-
sort(anc2, strlen(input));
-
for(i=0; i<1480; i++) {
-
for(j=0; j<strlen(file[i]); j++) {
-
if(anc2[j] == anc1[i][j]) {
-
x++;
-
}
-
if(x == 10) {
-
printf("String is: %s", file[i]);
-
}
-
}
-
x=0;
-
}
-
}
-
All it does absolutley nothing. Does'nt print out anything, and I don't know why.
The word list is very big.
Also, move the x = 0 line to the top of the loop because it will be undefined the first time: -
for(i=0; i<1480; i++) {
-
x = 0;
-
for(j=0; j<strlen(file[i]); j++) {
-
if(anc2[j] == anc1[i][j]) {
-
x++;
-
}
-
if(x == 10) {
-
printf("String is: %s", file[i]);
-
}
-
}
-
// x=0;
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: superprad |
last post by:
"X-No-Archive: yes"
what I am looking for is
1. To create a list of different words of various lengths(1-15) using
A-Z,a-z,0-9 and punctuations.Basically anything that could be found on
a...
|
by: CV |
last post by:
How can I match 'n' number of neighbouring words of a pattern using regular
expressions?
For example, suppose I am looking for the pattern "length xyz cm" in some
text. where xyz is a number -...
|
by: Rick |
last post by:
I have a program that reads from a file. In the file are a series of
words. I read in all the words into a string array, find the average
length, count the number of words, display the longest...
|
by: Sling |
last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) &
words(s).
word(s,i) returns the ith word in the s(tring), and words(s) returns the
number of words within the s(tring)....
|
by: Jim Carlock |
last post by:
Looking for suggestions on how to handle bad words that might
get passed in through $_GET variables.
My first thoughts included using str_replace() to strip out such
content, but then one ends...
|
by: abraxas |
last post by:
Ok maybe someone here can help me. I have been learning c++ and have
been toying with some basic programming and have run into something
that I would have assumed would have been fairly easy. I...
|
by: Jay |
last post by:
How would I be able to grab random words from an internet source. I'd
like to grab a random word from a comprehensive internet dictionary.
What would be the best source and the best way to go...
|
by: dmurray14 |
last post by:
Hey guys,
I'm a C++ newbie here - I've messed with VB, but I mostly stick to web
languages, so I find C++ to be very confusing at times. Basically, I am
trying to import a text file, but I want...
|
by: Xernoth |
last post by:
Hi,
I have an exercise that requests the following:
Write a function that reads words from an input stream and stores them
in a vector.
Use that function both to write programs that count the...
|
by: bugboy |
last post by:
I'm a beginner at this and am confused...
I have three tables:
1. words / wordpk, word
2. definitions / definitionspk and definition
3. associations / wordpk, definitionspk
'words' holds...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |