0

Hello Cereal,

This is for a Windows OS. I am not familiar with PHP. Hence, I only use CURL. I have provided an example of IPs below. You can just simply save this as a text file.

192.168.1.5
192.168.1.6
192.168.1.7

So, what is going to happen is I will create a batch file that would call something like this:

curl http://192.168.1.5/cgi-bin/history > printer1.txt

Printer1.txt will be the output. The output contains the values generated from the web interface of 192.168.1.5.

Thanks for the help.

0

Hello Guys,

I apologized if I may have misplaced this post as I cannot see CURL on any category.

Here is my situation. I am trying to create a batch file which will pull up information from a fleet of devices via its web interface. I am using CURL to do that. The output will be 1 file for each device. I created a text file that lists all the IP address of the devices.

Below is the command I usedd for just one device:

curl http://<IP>/cgi-bin/history > <nameOFfile.txt>

Any help will be much appreciated.

Thanks.

0

Hi all,

I was making a program as one of our activities. The output should be something like this:
[IMG]http://img10.imageshack.us/i/ss1qh.jpg/[/IMG]

When I press on Display Output, it should look like this:
[IMG]http://img29.imageshack.us/i/ss2pa.jpg/[/IMG]

However, when I have to Insert a record, the added record should be added on the record when I have to display them. I have my program below, but I can't seem to get how to do that. Please bear with me.

[CODE]#include<stdio.h>

include<stdlib.h>

define x 20

int index=1,ans,as,ctr;

struct student
{
char studname[20];
char course[6];
int yr;
} studinfo [x];

void addrec()
{
printf("\n\nHow many record(s) do you want to store? ");
scanf("%d",&as);
printf("\n\n");

for(ctr=0;ctr<as;ctr++)
{
    printf("Record Number %d\n\n",index++);
    printf("Name        : ");
    scanf("%s",&studinfo[ctr].studname);
    printf("Course      : ");
    scanf("%s",&studinfo[ctr].course);
    printf("Year        : ");
    scanf("%d",&studinfo[ctr].yr);
}

}
void insertrec()
{
printf("\n\nHow many record(s) do you want to Add? ");
scanf("%d",&as);
printf("\n\n");

for(ctr=0;ctr<as;ctr++)
{
    printf("Record Number %d\n\n",index++);
    printf("Name        : ");
    scanf("%s",&studinfo[ctr].studname);
    printf("Course      : ");
    scanf("%s",&studinfo[ctr].course);
    printf("Year        : ");
    scanf("%d",&studinfo[ctr].yr);
}

}
void displayrec()
{
system ("cls");
printf ("\n\n\t\t Student Name \tCourse \tYear\n\n");
for(ctr=0;ctr<as;ctr++)
{
printf("\t\t %s\t\t %s\t %d\n",studinfo[ctr].studname,studinfo[ctr].course,studinfo[ctr].yr);
}
printf ("\n\n");
}

void main()
{
start:
printf("\n[1]-ADD NEW RECORD\n[2]-INSERT RECORD\n[3]-DISPLAY RECORDS\n[4]-EXIT\n\n");
printf("Enter desired transaction: ");
scanf("%d",&ans);
if(ans==1)
{
addrec();
goto start;
}

    else if(ans==2)
   {
    insertrec();
    goto start;
   }

  else if(ans==3)
  {
    displayrec();
    goto start;
  }
 else 
     printf("\nYou have chosen to EXIT this program!\n");

}[/CODE]

0

[QUOTE=prushik;1444733]That is essentially what I suggested, except with a goto statement instead of recursion. I personally never use goto in C because it can make your code look sloppy and hard to follow.
If you can't figure out what was wrong with your original code, follow the code line by line manually. Take special notice of what will happen when the user enters a bad value the second time. Following you code manually is almost always a good way to find bugs like that.[/QUOTE]
Honestly, I do know how to use one. And I'm not prohibited to use either. Can you please tech me how?

0

[QUOTE=prushik;1444151]Well, its pretty simple. Just call withdraw() again. Something like this:
[CODE]if (ab>=wdraw)
{
ab=ab-wdraw;
printf ("\n\nAmount withdraw: %d",wdraw);
printf ("\nNew balance: %d\n\n", ab);
}
else
{
withdraw();
}[/CODE]

You see, in my example, if you try to withdraw too much, then it goes back to the beginning of the withdraw() function.
I'm assuming this is a homework assignment. You may not have learned recursion yet in your class, its very useful. However, if your teacher/professor does not allow you to use concepts that you haven't learned yet, you may need to look for an alternate answer. If that is the case, think about something like a while loop, a for loop could also work, but the syntax would look a little silly. If this is not homework, then I recommend recursion, as that is the cleanest way to do it. If you have learned recursion before, use it, professors love students that use recursion.[/QUOTE]

Yeah, it is one of the exercises given...I have my solution to code below but still trying to figure out the problem with the code above...Here is my complete code to the working one:

[CODE]#include <stdio.h>
int d, w, cb, trans,res;

Deposit()
{
printf("\nYour current balance is %d\n",cb);
printf("\nPlease enter amount to be deposited:");
scanf("%d",&d);
cb+=d;
printf("\nYou have successfully deposit to your account!!!");
printf ("\nYour previous balance is %d\n", cb-d);
printf("\nYour current balance is %d\n",cb);
return(0);
}

Withdraw()
{
n:
if(cb>0)
{
printf("\nEnter Withdraw Amount:");
scanf("%d",&w);

    if(w>cb)
    {
        printf("\nSorry!You have Entered an Insufficient amount!\n");
        printf("\nPlease ...
0

[QUOTE=Banfa;1443510]The if statement (line 32 - 48) needs to be inside the else block (line 27 - 31) because that code should only be run if ab != 0. The return at line 24 then becomes redundant (it is not uncommon for coding standards to ban returns in the middle of functions).

Then you need to put a big loop round the new contents of the else block, remove the second request the amount and go round the loop if !(ab>=wdraw) to get more input.

The basic design should be that there is only a single place that requests the input of the value that you then test and use if it is valid. if it is not valid you output an error and start the process again.[/QUOTE]

Can you please tell me how? I'm not that good yet with C. Thanks.

0

Hi there,
Kindly see my attached code below. This is already running however, I do have a little problem with the WITHDRAWAL part.

For example:
My current balance is 500 and I withdraw 501. It will tell me at first that I have insufficient funds and would prompt me to enter another amount. However, If I enter 501. It will tell me that I have -1 as my New balance which should't be. What I want is it will keep me prompting an mount either less than or equal to my current balance so that it will not display a negative new balance.

[CODE]#include <stdio.h>

include <stdlib.h>

int dep=0,ab=0,wdraw=0;
void acctbal()
{
printf ("\n\n---Account Balance---\n\n");
printf ("\n\nYour Current Balance is: %d\n\n",ab);
}
void deposit ()
{
printf ("\n\n---Deposit---\n\n");
printf ("Enter Amount :");
scanf ("%d",&dep);
ab=ab+dep;
printf ("\n\nAmount deposited: %d",dep);
printf ("\nNew Balance: %d\n\n",ab);
}
void withdraw ()
{
if (ab==0)
{
system("ds");
printf ("\n\nplease be reminded that your current balance is: %d\n", ab);
return;
}
else
{
printf ("\n\n--Withdraw--\n\n");
printf ("Enter Amount :");
scanf ("%d", &wdraw);
}
if (ab>=wdraw)
{
ab=ab-wdraw;
printf ("\n\nAmount withdraw: %d",wdraw);
printf ("\nNew balance: %d\n\n", ab);
}
else
{
printf ("\n\n Insufficient Funds--\n");
printf ("please be reminded that your current balance is: %d\n",ab);
printf ("\n\n---Withdraw---\n\n");
printf ("Enter new amount: ");
scanf ("%d",&wdraw);
ab=ab-wdraw;
printf ("\n\namount withdraw: %d",wdraw);
printf ("\n\nNew balance: %d\n\n",ab);
}
}
void main()
{
int ans;
char oper;
a:
system ("ds");
printf ("\n\nTransactions\n\n");
printf ("D- Deposit\n");
printf ("W- Withdraw\n");
printf ("A- Account Balance\n");
x: ...

0

Here is the complete code of the program:

[CODE]#include <stdio.h>

include <stdlib.h>

void main ()
{
int as,x[100],ctr,j,flag;
printf ("\nEnter array size: ");
scanf ("%d",&as);
printf ("\nEnter the values of your array:\n ");

for (ctr=0;ctr<as;ctr++)
{
do{
printf ("\nx[%d]= ", ctr);
scanf ("%d", &x[ctr]);
if(ctr>0)
{
for(j=0;j<ctr;j++)
{
if(x[j]==x[ctr])
{
flag=1;
printf("\n Number Already Exist!,Enter Another Value\n"); // add this
break;
}
else flag=0;
}

}
else flag=0;
}while(flag==1);
}
}[/CODE]

Thanks to Vinitmittal for the answer... Two thumbs up!!!

0

[QUOTE=vinitmittal2008;1402549]I checked your output file.. its working friend.. just add a printf statement just after flag=1 statement as i edited in my above post.

you have already passes x[0]=3 thats why its not taking same value in x[1], just add this
[CODE]
flag=1;
printf("\n Number Already Exist!,Enter Another Value\n"); // add this
break;
[/CODE][/QUOTE]

It worked..Thank you so much...

0

[QUOTE=vinitmittal2008;1402512]declare a int variable flag and you can try something like below code

[CODE]
for (ctr=0;ctr<as;ctr++)
{
do{
printf ("\nx[%d]= ", ctr);
scanf ("%d", &x[ctr]);
if(ctr>0)
{
for(j=0;j<ctr;j++)
{
if(x[j]==x[ctr])
{
flag=1;
printf("\n Number Already Exist!,Enter Another Value\n");
break;
}
else flag=0;
}

}
else flag=0;
}while(flag==1);
}

[/CODE][/QUOTE]

thanks for the code. however, it didn't work[IMG]http://img13.imageshack.us/img13/3739/30935451.jpg[/IMG]

0

[QUOTE=vinitmittal2008;1402476]>> where it should prompt the user to enter another value for x if the value corresponds to either the values of other elements.

[CODE]
for (ctr=0;ctr<as;ctr++)
{

printf ("\nx[%d]= ", ctr);
scanf ("%d", &x[ctr]);
// here that condition should be checked
}

[/CODE][/QUOTE]

Let's say for example the program will prompt me like this:
Assuming that the size of the array is 6

Enter the values for array

x[0]= 1 <<<<== for example I will enter 1
x[1]= 2 <<<<== for exmple I will 2.it will then proceed to prompt me to enter x[2]
x[2]= 2 <<<== however if I enter 2 on x[2], the output should be something like:
"Number already exist.Enter another number."
x[2]= <<<=== the user should enter another number or else it will continue to prompt x[2] until the user can enter numbers different from x[0] and x[1]...

Thanks...

0

[QUOTE=Ancient Dragon;1402364]>>void main ()

main() always returns an integer -- its never void even if your compiler allows it. Many compilers won't let you declare void main(). Get into the habbit of writing programs correctly and always declare it as [icode]int main()[/icode] or [icode]int main(int argc, char* argv[])[/icode]

I could offer some other suggestions to fix your code but won't because you failed to post the code between code tags.[/QUOTE]

I am not really quite following you about posting the code between code tags. Can you please tell me exactly what I need to do?

0

Hi Guys,

Wanted some help with my code.

This should be the OUTPUT.

Enter the size of your array: (array size should be 1-100)
Enter values of your array:
x[0]= (any integer)
x[1]= (any integer but not equal to the value of x[0])
x[2]= (any integer but not equal to the value of either x[0] or x[1])

and so on and so forth

it will then sort the array like the one below:

X[0]=1 x[1]=2 x[2]=3 ......

Enter Number to be Search: (any number either within the array elements or outside of it)

Here is the code below. Everything is working except to the part where it should prompt the user to enter another value for x if the value corresponds to either the values of other elements.

[code]#include <stdio.h>
void main ()
{
int pass, found, fh, sh, mid, as,x[100],ctr,ns,j,temp;
printf ("\nEnter array size: ");
scanf ("%d",&as);
printf ("\nEnter the values of your array:\n ");

for (ctr=0;ctr<as;ctr++)
{
printf ("\nx[%d]= ", ctr);
scanf ("%d", &x[ctr]);

    }
for (ctr=0;ctr<as-1;ctr++)

{
for (j=0;j<as-1;j++)
{
    if (x[j]>x[j+1])
    {
        temp=x[j];
        x[j]=x[j+1];
        x[j+1]=temp;
    }
}
}

printf ("\n\n--Sorted Series--\n\n");
for (ctr=0;ctr<as;ctr++)
{
printf ("\t x[%d]= %d", ctr,x[ctr]);

}
pass=0;
found=0;
fh=0;
sh=as;
printf ("\nEnter number to be search: ");
scanf ("%d", &ns);
do
{
mid=(fh+sh)/2;
if (ns<x[mid])
sh=mid-1;
else if (ns>x[mid])
fh=mid+1;
else
found=1;
pass++;
}
while (fh<=sh &&!found);
if (found)
printf("\nFound at index %d\n ",mid);
else
printf ("\nNot found\n");
printf("\n\nNumber of passes: %d\n\n ",pass);
}[/code]