C/C++ :: Scan A Directory Recursively

Dec 19, 2014

I'm writing a C++ module that is meant to recursively scan a directory and I'm curious what yall think of my strategy.

The program is a music player and so I'm trying to make the directory scanner as lightweight and efficient as I can. I've decided I want to scan the files in two passes- first I just want to get a list of all music files that are found in a directory/subdirectories and then I want to process the list and search for id3s/other tags.

As I'm a scanning the directory, I've decided to store the temporary list in a linked list where each node is containing an array of 100 strings. I did this because I obviously don't know how long the list will be and I from my understanding of the C++ vector class it basically just makes over sized arrays and moves them when it runs out of space. That sounded rather clunky to me, as did a traditional linked list.. I didn't see the point of allocating memory that many times in a row.

View 3 Replies


ADVERTISEMENT

C++ :: Recursive Directory Scan - Can Use Multi-threading For Speed?

May 11, 2014

In our Qt application, we have to load several files on application start-up starting from a root directory.

We are recursively scanning the directories and loading the files.

The total time it takes is about 12 seconds. Can we reduce this time if we use multi-threading?

I have heard that multi-threading does not work everywhere and it increases code complexity and debugging issues.

Would multi-threading solve the above problem? We want it to be platform independent (Mac, Linux, Windows).

View 9 Replies View Related

C Sharp :: Scan Directory Selected From Treeview Control

Jan 20, 2015

I am doing "Virus Tracking System" Project. I have to scan the directory selected from treeview ....

View 9 Replies View Related

C++ :: Deleting A Character Recursively?

Mar 18, 2013

I'm having trouble deleting a character inputted by the user recursively..

1- Should I be doing it this way where it returns the character one by one to the console?

2- Is there a way actually rebuild the string to "delete" these occurances of the key?

//This program deletes a character inputted by the user recursively
#include <iostream>
using namespace std;
char find (char *a, char key)//Function gets passed array (but makes it a pointer) and key

[code]....

View 5 Replies View Related

C/C++ :: How To Get Linked List Size Recursively

Mar 2, 2015

suppose that the class LinkedBag did not have the data member item_count_. Revise the method getCurrentSize so that it counts the number of nodes in the linked chain a. iterartively b. Recursively[

LinkedBag.h
template<class ItemType>
class LinkedBag : public BagInterface<ItemType> {
public:
LinkedBag();
LinkedBag(const LinkedBag<ItemType>& a_bag);
LinkedBag<ItemType>& operator=(const LinkedBag<ItemType>& right_hand_side);
virtual ~LinkedBag();

[code].....

View 6 Replies View Related

C++ :: Deleting Linked List Nodes Recursively

Jun 25, 2014

I am creating a Linear linked list in c++. I've written all the functions for it, but now I want to try and do them using recursion.

I managed to make functions for adding and displaying nodes on the list, but I am stuck on the function for removing nodes. First I want to try and write a function the removes the last item on the list. But for some reason my code isn't working properly.

Here is the code :

void removeLastItem(node * &head) {
if(!head) {
delete head;
head = NULL;

[Code] ....

NODE - My structure name
NEXT - The pointer to next element.
HEAD - The first (head) pointer.

The couts in the if statements are just for testing. In fact after I Run my program it does as it is supposed - enters the second if /b]case as many times as there are elements and then executes the first [b]if statement. But for some reason it does not delete the actual node.

View 2 Replies View Related

C/C++ :: Recursively Displaying Folder And Subfolder Contents

Apr 20, 2014

I'm trying to recursivly display the contents and sub contents of a folder. Here is the function that gets called:

void Ls(string wrkDir, bool recursive) {
DIR *dirStream;
dirStream=opendir(wrkDir.c_str());
if(dirStream==NULL)
return;
dirent *ep;

[Code] ....

what is happening is once it goes through all the sub-directories in the first folder, it goes right back into it. Also when it approaches a file that isn't a directory, it doesn't pop out of the stack, instead it adds the name of the next file to the path and tries to open that. How do i test if the current path is a directory using only standard c/c++ calls. Can't use boost or wxWidgets.

View 14 Replies View Related

C++ :: Check If Binary Search Tree Is Full Or Not Recursively?

Dec 5, 2013

How would I check if a binary search tree is full or not recursively?? ?

View 1 Replies View Related

C/C++ :: Code That Recursively Calls Itself And Prints Given Digits In Ascending Order

Mar 15, 2015

I'm trying to implement a code that recursively calls itself and prints the given digits in ascending order, i.e. if the number is 5, then the function will print 1 2 3 4 5. I cannot use loops in any way!

The problem I have is with keeping my variable i at a set value each time the function calls itself.

void print_ascending(int n){
int i = 1;
if(i < n) {
printf("%d", i);
i++;
print_ascending(n);
}
}

Of course, the problem with this code is it will re-initialize the variable i to 1 every single time and infinitely loop to print 1.

View 11 Replies View Related

C/C++ :: Recursively Building Cons Cell Structure Via Recursive Descent

Apr 25, 2015

I'm currently working on a Scheme Interpreter written in C. I'm trying to create a cons cell structure via recursive descent parsing, except instead of just having the car and cons, I also have a field that holds the token that I receive from the lexical analyzer (which was provided to us). The struct for what I'm describing is as such:

typdef struct node node;
typedef node* list;
struct node {
char* symbol;
list car;
list cdr;
};

Thus a cons cell would be (with a node represented as [symbol][car][cdr]), [null][car][cdr], while a symbol would be [symbol][null][null].

In the top answer for a similar question on Stack Overflow, one of the suggestions was to put the tokens into a stack as the input is recursively parsed, and then from that stack input it into the cons cell structure.

This is something that I'm working towards now, as it is easier for me to understand and I already have implemented a stack in C before, but I know that I can just build the structure recursively, I'm just not sure how. The following is code that I have:

list s_expression() {
list local;
list temp;
if (strcmp(token, "(") == 0) {
strcpy(token, getToken());

[Code] .....

s_expression is supposed to return a pointer to a recursively built cons cell structure. I'm just having issues figuring out when to call getToken(), as I either call getToken in the wrong spot and unintentionally skip over a token, or I call getToken() when I'm done getting all of the tokens, thus causing my program to continue searching for a token from user input instead of continuing on with the rest of the program.

When should I be calling getToken()?

In addition, what would be better, recursively building the cons cell structure as you go through the user's input, or putting all of the tokens into a stack and then building the cons cell structure using that stack?

If needed, I can post the lexical analyzer that's been provided to us. Also, for S_expression(); showing up as S_exp<b></b>pression();, I'm not sure what happened there. I copied this post from my question on stack overflow.

View 12 Replies View Related

C :: How To Get Scan Code Of ESC Key

Sep 17, 2014

i wrote the following code :

Code:

#include<stdio.h>#include<conio.h>
#include<stdlib.h>
int a[][4] = {15,9,10,25,6,2,4,7,32,19,42,8,21,17,18,0};
void boxes();
void display();
void main()
{int ch,r=3,c=3,t;

[Code]...

not able to esc when i press esc key.how to get rid of this.

View 4 Replies View Related

C :: Scan Value For Specific Data

Dec 13, 2014

I created a program that will create a file and print a list on it. Here is the code for my program:

Code:
int controlvalue(void) {FILE *controlvalue;
controlvalue = fopen("something.txt", "a+");
/* Series of fprintfs */
fclose (controlvalue);
return 1;}

Here is an example list created by my program:

Code:
[Gifts]Candy=45
Chocolate=32
Toy=128
Robot=754
Doll=1492
Star=21
Phone=72
Skateboard=87
Frame=314
Days=365
Perfume=421

I want to get the value of "Skateboard" on file. So I need to read 9 lines. On the 9th line, the gets() loop will stop. But, what if I only want to get the value of "Skateboard" as integer (87) and not a string? Also, is it possible to scan the value of Skateboard if it's located on a different (or unknown) line?

View 1 Replies View Related

C :: How To Scan And Print Integer

Jan 28, 2013

This is my code:

int main() {
int num;
printf("Please enter a number: ");
scanf("%d", num);
printf("%d", num);
return 0;
}

when i compile and run it, it stops working and doesn't printf the integer.

View 3 Replies View Related

C :: Multiple Entries Into Scan?

Sep 19, 2014

How would I be able to let the user enter multiple heart rates which would all be separate.

Code:

printf("Enter your recorded Heart Rates ");
scanf("%d", &in_rate);
//formulas
if (gender == 'm'){
target = 226 - age;
} else if (gender == 'f'){

[Code]...

View 1 Replies View Related

C :: How To Scan Text File And Put It Into Array

Mar 4, 2013

This is my text file.

bak kut teh[tab]888.0[tab]989.0
spicy chicken nugget[tab]999.0[tab]978.0

I'm experiencing some problem in trying to scan and put it into an array for the food names (e.g an array for food which consist of bak kut teh and spicy chicken nugget) and another 2 array for the other individual integer into C. However there seem to be some problem with my code.

Is there a difference if I use both tab and space instead of space for all?

Code:
#include<stdio.h>
int main() {
FILE *fp;
char food[100];
char buff[BUFSIZ];
float num;

[Code] ....

View 2 Replies View Related

C :: Using Fgets() To Scan A Data Before A Delimiter

Dec 21, 2014

Is it possible to fgets() the string (or word) only after a delimiter? I yes then how?

Example: Code: printer, scanner, machine

Also, how can I sscanf() a string with an indefinite number of sizes and assign it to only one variable?

Example:

Code:
str = "I Love C programming 9000";
sscanf(str, "%s %d", strvar, intvar);

View 13 Replies View Related

C++ :: Parallel Scan Of Sorted Sequences?

Feb 4, 2015

I need to take an unknown amount of sorted files and then output any number that is in at least half of them... I know I need to read in the files to a vector and then iterate through them all at the same time looking at the lowest number first and so on. But I am stuck at the point of taking an unknown amount of files and putting them in a container.

This is what I have so far but the vector isn't working and I think I should be putting each file into its own vector.

string get_file(string filename)
{
ifstream in(filename);
if (in)

[Code]....

View 3 Replies View Related

C :: How To Scan In Numbers From File And Find The Largest

Oct 4, 2013

I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.

input file text (first number is num of auctions, after that it's num of bids, then the bids):

5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23

Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!

The silent auction raised $2470.00 for charity!

Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>

[Code].....

View 4 Replies View Related

C :: How To Prompt User To Scan Numbers Into Array

May 17, 2013

i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:

Code:

float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);

The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.

how to scan numbers into an array so that they can be used for later use?

View 9 Replies View Related

C/C++ :: Scan Through One String To Find A Letter That Also Appears In Another?

Feb 3, 2015

I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:

char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}

but it continues to return wrong values idk what I'm doing wrong.

View 4 Replies View Related

C++ :: How To Scan Multiple Vectors For Common Elements Efficiently

Nov 6, 2013

we conform to the ISO C standard and this snippet of code : Code: vector<tree*> *leaves = new vector<tree*>[num_threads]; where num_threads is specified from command line arguments so not dynamically allocating it violates the standard.

Let's also assume num_threads is greater than one.

What I want to do is scan each vector in leaves for duplicates. If any two vectors in the set have matching addresses, they both immediately go onto the "unsafe" pile and will no longer be subject for testing.

If a vector clears one vector, we test it against the others in the set.

So if we have 3 vectors, A, B and C we test A against B then A against C. For efficiency, we then then just test B against C.

Like I said, I want a "safe" and "unsafe" pile. Every vector in "safe" is fully unique while every vector in "unsafe" is not unique.

I thought about just using a for-loop to loop through leaves and then iterate through each element but I'm not sure if that'll work just right out of the box.

View 14 Replies View Related

C/C++ :: Program To Scan Number And String Then Print Them To A File

Mar 19, 2015

I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :

1 test
2 dream
3 code

then output (in data.list file) would be:

1 test
2 dream
3 code
3 code

I also changed the program code so that it reads from data.list file. even here it duplicates last line!

so when program reads the info above saved in data.list it would be:

1 test
2 dream
3 code
3 code
3 code

here's the code for writing:

#include <stdio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;
fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist
while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X

[Code]...

and the one for reading from file:

#include <stdio.h>
#include <conio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;

[Code]...

How do I fix this behavior??

View 3 Replies View Related

C++ :: Shop Database - Take Customers ID And Scan Through A Text File Then Print Out Info

Apr 10, 2013

I have to create a small data base for a shop. One of the functions i am creating is taking a customers ID and scanning that through a text file and to print out the info about that customer. What i am having trouble with is where do i insert the string compare in my program?

//declaring array for input of customer ID
int customer_ID [20];
printf("Please enter the customer ID:");
gets( customer_ID ); //users input stored in the array

[Code] .....

View 2 Replies View Related

C++ :: Add Data To Text Files Which Are Required To Store 3D Scan Data

Jul 10, 2013

I have written the following code to add data to text files which are required to store 3D scan data (I have to calculate the y-coordinate). My code seems to work except that it stops working when I want to create more than ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Code is shown below.

#include <string>
#include <locale>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

[Code] ....

View 1 Replies View Related

C++ ::  Creating A New Directory?

May 11, 2013

How do you create a new directory in C++? I would like to do this using the standard library and no external, third party or non standard libraries/headers. I need to do this without calling system() or system("mkdir").

View 7 Replies View Related

C++ :: How To Change Directory

Apr 24, 2014

How to change directory in c++ ( windows ) I want to go to the folder "example2" and I delete some files and then return to the original folder c++ - windows

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved