dose any one know how exactly to do recursion in C. i am trying to simply make a program to list files in a directory and recursivly goes through each sub directory and list the files they contain. i cant seem to get it to go more than one levle deep, because once i am down one level my check to see if the file i have encountered is a directory always returns 0. i am using the macro in the sys/stat.h and unistd.h libraries which is S_ISDIR(statBuffer.st_mode);\nany help on this topic would be great
125484
You need to think about your exit return.\n\nfunction yourfunction(isfinished)\n{\nif (isfinished==false)\n{\ndo something if it's done isfinished=true\nyourfunction(isfinished);\n}\n}\npublic void main()\n{\nbool isfinished='false';\nyourfunction(isfinished);\n}\n\nSomething like that.
62710
C solution:\n\nint nr[20];\nint valid=1,i,j;\nint main(int argc, char **argv){\nfor (i=0;(i<20)&&(valid);i++){\n scanf("%d",&nr[i]);\n if (nr[i]<10)||(nr[i]>100){\n  printf("Invalid number");\n  valid=0;\n }\n for (j=0;j<i;j++)\n  if (nr[j]==nr[i]){\n    printf("Duplicate number");\n    valid=0;\n  }\n}\n}
299550
u didn't mentioned Language ...this is in C....\n\nint i, j, n;\nprintf("Enter no of lines");\nscanf ("%d",&n);\nfor (i=0;i<n;i++)\n{\n    for(j=0;j<=i;j++)\n    {\n        if(j==0||j==(i+1))\n          printf(" 1");\n        else\n          printf(" %d" ,i+2);\n     }\n     printf("&#92;n");\n}
132950
void StrReverse4(char *str)\n{\n    if(*str)\n    {\n        StrReverse4(str+1);\n        putchar(*str);\n    }\n}\n\nTry this code it might work
674588
In your printf("%d%c");\nyou do not specify any variables or data to be printed. \nPrintf() "pretends" there is data anyway and prints it out (what the 0 and X are is whatever is on the stack at the time - return addresses usually).\n\ntry  printf("%d%c", 123, 88 );
470702
The answers to this excruciatingly SIMPLE question are truly shocking, as none of them are 100% correct.\n\nIso R: if the parameters aren't refs, how is the result of the swap going to be returned??\n\nTerry: It is perfectly acceptable to use return inside a void function, as long as no value is returned --which doesn't happen here.  The return statement simply, immediately ends the execution of the current function.\n\ncherankrishnah: WHAT should be returned as an int??  The function swaps two ints to get them in the right order.  How can you swap TWO ints and only return ONE?\n\nAshutosh: See my comment on Terry's answer.  At least you got the missing semicolon.\n\nGeez. With programmers like you, no wonder software development has such a bad reputation.\n\nAs Ashutosh remarked, the mistake is probably the missing semicolon (;) after swap.  Since it's missing, the parser cannot handle the return statement that follows it.\n\nAs I wrote, the returns are perfectly legal, only they are not necessary in this case.  The following code should be sufficient:\n\nvoid order2(int& m, int& n)\n{\n    if (m > n)\n    {\n        swap(m,n);\n    }\n}
58109
Depends on your compiler and operating system. However, you can probably use the system() call from the C library (you can call that from a C++ program) or one of the exec functions. These exist on most Windows compilers and Linux/Unix too.\n\nhttp://www.gnu.org/software/libc/manual/html_node/Executing-a-File.html\n\nhttp://www.gnu.org/software/libc/manual/html_node/Running-a-Command.html#Running-a-Command\n\nNote that if you are not using gcc, your versions may be a little different than these.
568732
#include <stdio.h>\n#include <dos.h>\n#include <conio.h>\n\n/********************************************/\n/*This program set the parallel port outputs*/\n/********************************************/\n\nvoid main (void)\n{\nclrscr();             /* clear screen */\noutportb(0x378,0xff); /* output the data to parallel port */\ngetch();              /* wait for keypress before exiting */\n}\n\njust check here you can get all info http://www.epanorama.net/circuits/parallel_output.html
73445
Lets examin the first output case you have, f.fact(3):\nThe first layer of this function call will have result = fact(3-1)*n.  This will of course call another layer of the fact function with result = fact(2-1)*n, and this will then call fact on 1. \n\nSince the base case for the recusion is 1, 1 will be returned.  And the function call will return values in reverse order.  So result = fact(2-1)*n will no be result = 1*2.  Which will then be returned to the function that called it, result =fact(3-1)*n is now result = 2*3. and that value is finally returned.\n\nThe key to understanding recursion is knowing what the basecase is.  If you can find the base case then evaluating the recursion is simply.  Just follow the function all the way through until you hit that base case, then work your back out example... 1 -> 2 -> 3 -> 4  then to get out we'd go 3 -> 2 -> 1.\n\nHopefully this helps.
487125
Chkdsk also checks file intergrity.  It can determine cross-linked files or file system corruption.  \n\nThis basically means that it checks the file against the Allocation table to make sure that everything is as it should be and that no part of an allocated filed is unaccounted for or showing incorrect entries.\n\nYou need to change to the C:&#92;windows &#92;system32 directory to run the DOS utilities
330960
/*\nOriginal Question:\nI am writing a C program in Solaris environment...if i\nwant to execute some system command i can do it using\nsystem("string to be executed")....but it accepts string\nonly. what if i want to pass some variables to system at\nrun time....suppose i was to use this commands at runtime\n"cat file1 file2 >file3"....how i wud pass the file names?\nany suggestions !  thnx in advance Amardeep Sidhu\n*/\n\n#include <stdlib.h>\n#include <stdio.h>\n\nint\nmain(int argc, char* argv[])\n{\n\n  /* First, get some values into variables */\n\n  char *str1 = "ls";\n  char *str2 = "-l";\n  char *str3 = "/tmp";\n\n  /* One common trick to using "system()" is */\n  /* to "sprintf()" the arguments into a buffer */\n  {\n    char buffer[100];\n    sprintf(buffer, "%s %s %s", str1, str2, str3);\n    system(buffer);\n  }\n\n  return 0;\n}
390615
Mn is close, but there are 2 errors:\n\n1) There is no len() function.  Use strlen() instead of len().\n\n2) He didn't allocate enough memory for the sprintf to fit the entire result string in the buffer.  The line needs room to store the &#92;n (or in windows, 2 chars - cr and lf ) in addition to the null terminator.  So, his code needs to add 2 instead of 1 to the length calculation.  \n\nTaking this a little further, the number of chars should be multiplied by the sizeof(t_char), which MIGHT NOT be 1 byte if the code is destined to use unicode.\n\nChances are, this is ascii, so the multiplication is unnecessary, but it is better to be safe than sorry.  Besides, if this was production code, you'd want to be able to use the same code in both places without any need to change it.  Nothing worse than having to go back and recalculate buffer manipulation code during a port.\n\nThe above subtleties demonstrate precisely how and why it is so very easy to make a mistake in c/c++, leading to a buffer underallocation or overwrite, and hence a security hole.
18313
Go to the Dos prompt. There is a program called sort.\n\nSort [unsorted file name] > [sorted file name]\n\nIf you want to concatenate all your files together first, that's a bit more tricky:\n\nCopy [file name 1] ABC.Txt\nType [file name 2] >> ABC.Txt\nType [file name 3] >> ABC.Txt\n.\n.\nSort ABC.Txt > ABC.Srt
217040
I can see by looking at it that it won't compile.\nYou don't have semicolons at the end of the lines.\n\nI you put in the semicolons and replace the comma in the for loop with the another semicolon, it will compile and run.\n\nHowever, I don't think that you will get what you expect.\n\nYou use x without initializing it. That means that x will take the value that is already in memeory at that address.\n\nNext you condition your while loop on (R!=R) which is always false, so the while loop never executes.\n\nWhat you will print out is the last value that was left in x which is a location on the stack. \nI'm running MS C++ in debug mode, so it fills in the bytes of x with the value CC so you can recognize it as uninitialized stack memory.\n\nLast, you compute S but never use it.
51966
ls -l | more\n\n( '|' is called pipe, to get this use 'shift' and '&#92;' keys)\n\nyou should use space bar to go to the next page of list
146317
If you want to convert a hex string to decimal, you\nneed to do two operations:\n\n- convert the hex string to a number\n- generate a decimal string from that number\n\nIf your system supported a full C implementation,\nit would be as simple as using scanf()/printf().\nI presume you're being asked to implement the\nprimitives yourself :-)\n\nTo convert a hex string to a number, you might\nimplement something like:\n\nint number = 0;\nwhile ((c = getchar()) != '&#92;n') {\n  if (c >= '0' && c <= '9')\n    number = (number<<4) + (c-'0')\n  else if (c>='a' && c<='f')\n    number = (number<<4) + (c-'a')\n  else if (c>='A' && c<='F')\n    number = (number<<4) + (c-'A')\n}\n\nThis could be cleaned up if you have access to the\n<ctype.h> macros [ie. isdigit() and tolower()].\n\nTo convert the number to a decimal string, you need\nto perform successive divisions by 10.  An 8051\ndoesn't have a hardware divide, but that's OK\nbecause you should have a software divide/remainder\nsubroutine.\n\nThere are two tricks to keep in mind.  First to\ngenerate the appropriate character for each digit,\nyou can treat a literal character string as an\narray.  For example:\n\nchar c = "0123456789ABCDEF"[i];\n\nwill assign the correct character to variable "c"\nbased on the value of "i" (if it is between 0 and\n15).\n\nThe other detail is that as you call the divide/\nremainder subroutine, you will generate the digits\nworking from least significant to most significant.\nTherefore, you'll want to fill an array from right\nto left.  Assuming you have a divide routine with\nthe prototype:\n\nint\ndivide(int dividend, int divisor, int *remainder)\n\nand you can use the "puts()" function to display the\ngenerated string, you might use something like:\n\nvoid\ntodecimal(int value)\n{\n  char buffer[20];\n  char*p = &buffer[sizeof(buffer)-1];\n  int remainder;\n  while (value != 0) {\n    value = divide(value, 10, &remainder);\n    *p-- = "0123456789ABCDEF"[remainder];\n  }\n  puts(p+1);\n}
378442
In your code, you do not need "system("start etc);": system( "cd dir_you_need" ) or "chdir(dir_you_need )" will be quite right :-)\nDo not forget to\n#include "stdlib.h"\nand do not forget that your "chdir" must get as an argument either full path or directory name relative to your current directory.