Hello,
I am practice the function in c and come across to the program ....
include
int main()
{
float a=15.5;
char ch ='C';
printit(a,ch);
return 0;
}
printit(a,ch)
{
printf("%f\n%c",a,ch);
}
I want to know that why the above program compile and not give the error as i understood so for is ...
1) The function in c must be declared with the specific prototype (but this program does not contain the prototype )
2)why the program give the output 'x'for the char variable
3)can the function in c are capable of accepting the value without being declared about type in parameters like what has done in the function declaration ....
plz.... help
Hey guys, had a basic doubt. What exactly is so totally different about languages like php that they are called scripting languages and languages like c are called normal programming languages?
I'm using jWYSIWYG in a form I'm creating that posts to a database and was wondering how you can prevent a malicious user from trying to inject code in the frame?
Doesn't the editor need brackets (which I'd normally strip during the post process) in order to display styles?
Hello everyone.
For my app, I need to print out a series of outputs and then accepts inputs from the user. What would be the best way of doing this?
Like:
print '1'
x = raw_input()
print '2'
y = raw_input()
Something like this, but it would go on for at least 10 times. My only concern with doing the above is that it would make up for poor code readability.
How should I do it? Should I create a function like this:
def printOut(string):
print string
Or is there a better way?
So I have this schedule visit page with two groups.
Group 1 contains a list of: Cases.
Group 2 contains a list of: Parties.
each group has a checkboxes next to its item for the user to select.
My Issue when i select a case and/or a party and save -- then go to the edit page of the visit i just saved and only my selected case is checked and the party i selected is not checked. After debugging i realized that the partyId is not being saved properly during the create page and thus not showing as selected or saved on the edit page.
I really need help on how to properly save the party selected and setting for it a value from the parameter. Here is my code of what i have for saving a case and would like to know how to properly save with party.
Controller
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(VisitViewModel viewModel, Guid[] associatedCasesSelected, Guid[] selectedParties)
{
if (!ModelState.IsValid)
{
viewModel.Time = _timeEntryHelper.Value;
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
var visitEntry = Mapper.Map<VisitViewModel, VisitEntry>(viewModel);
...
viewModel.CasePartyIds = selectedParties;
try
{
_visitEntryService.Create(visitEntry, associatedCasesSelected);
this.FlashInfo(string.Format(Message.ConfirmationMessageCreate, Resources.Entities.Visit.EntityName));
}
catch (RulesException ex)
{
ex.CopyTo(ModelState);
}
if (ModelState.IsValid)
return RedirectToAction("Edit", "Case", new { caseId = viewModel.CaseId });
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
VisitEntryService
public void Create(VisitEntry visitEntry,IList<Guid>caseIds)
{
EnsureValid(visitEntry);
_visitEntryRepository.Save(visitEntry);
caseIds = AddCurrentCaseToCases(visitEntry.CaseId, caseIds);
foreach (var caseId in caseIds.Distinct())
{
var visit = new Visit {CaseId = caseId, VisitEntryId = visitEntry.VisitEntryId};
_visitService.Create(visit);
}
}
AddCurrentCaseToCases
private static IList<Guid>AddCurrentCaseToCases(Guid caseId, IEnumerable<Guid>caseIds)
{
var cases = new List<Guid>();
if (caseIds != null)
{
cases.AddRange(caseIds);
if(!caseIds.Contains(caseId))
cases.Add(caseId);
}
else cases.Add(caseId);
return cases;
}
VisitService
public Visit Get(Guid visitId)
{
return DataContext.Visits.SingleOrDefault(v => v.VisitId == visitId);
}
public void Save(Visit visit)
{
if(visit.VisitId == Guid.Empty)
{
visit.VisitId = Guid.NewGuid();
DataContext.Visits.InsertOnSubmit(visit);
}
else
{
var currentVisit = Get(visit.VisitId);
if (currentVisit == null) throw RepositoryExceptionFactory.Create("Visit", "VisitId");
}
DataContext.SubmitChanges();
}
Any TIPS or IDEAS is greatly appreciated at this time :)
The entitiy for the parties will be VisitEntryParty
Hi,
How can i copy multiple char* variables into one char* at single instance operation.
say i have
char* text1 = "Hello";
char* text2 = "World";
i want to copy text1, text2 and '2' and "12345" into char* text3 in single function call.
I need to write two versions of the same application, one in .NET and the other one in Java.
So I'd like to write a single test suite, and then use it against both codebases.
Which testing tool would you advise me to use?
I've this program which finds substring in a string. It works for small inputs. But fails for long inputs. Here's the program:
//Find Substring in given String
#include <stdio.h>
#include <string.h>
main()
{
//Variable Initialization
int i=0,j=0,k=0;
char sentence[50],temp[50],search[50];
//Gets Strings
printf("Enter Sentence: ");
fgets(sentence,50,stdin);
printf("Enter Search: ");
fgets(search,50,stdin);
//Actual Work Loop
while(sentence[i]!='\0')
{
k=i;j=0;
while(sentence[k]==search[j])
{
temp[j]=sentence[k];
j++;
k++;
}
if(strcmp(temp,search)==0)
break;
i++;
}
//Output Printing
printf("Found string at: %d \n",k-strlen(search));
}
Works for:
Enter Sentence: good evening
Enter Search: evening
Found string at 6
Fails for:
Enter Sentence: dear god please make this work
Enter Search: make
Found string at 25
Which is totally wrong. Can any expert find me a solution?
P.S: This is kinda like reinventing the wheel since strstr() has this functionality. But I'm trying for a non-library way of doing it.
I have a UNIX native executable that requires the arguments to be fed in like this prog.exe < foo.txt.
foo.txt has two lines:
bar
baz
I am using java.lang.ProcessBuilder to execute this command. Unfortunately, prog.exe will only work using the redirect from a file. Is there some way I can mimic this behavior in Java?
Of course, ProcessBuilder pb = new ProcessBuilder("prog.exe", "bar", "baz"); does not work.
Thanks!
test code:
void modify_it(char * mystuff)
{
char test[7] = "123456"; //last element is null i presume for c style strings here.
//static char test[] = "123123"; //when i do this i thought i should be able to gain access to this bit of memory when the function is destroyed but that does not seem to be the case.
//char * test = new char[7]; //this is also creating memory on stack and not the heap i reckon and gets destroyed once the function is done with.
strcpy_s(mystuff,7,test); //this does the job as long as memory for mystuff has been allocated outside the function.
mystuff = test; //this does not work. I know with c style strings you can't just do string assignments they have to be actually copied. in this case I was using this in conjunction with static char test thinking by having it as static the memory would not get destroyed and i can then simply point mystuff to test and be done with it. i would later have address the memory cleanup in the main function. but anyway this never worked.
}
int main(void)
{
char * mystuff = new char [7]; //allocate memory on heap where the pointer will point
cool(mystuff);
std::string test_case(mystuff);
std::cout<<test_case.c_str(); //this is the only way i know how to use cout by making it into a string c++ string.
delete [] mystuff;
return 0;
}
in the case, of a static array in the function why would it not work.
in the case, when i allocated memory using new in the function does it get created on the stack or heap?
in the case, i have string which needs to be copied into a char * form. everything i see usually requires const char* instead of just char*.
I know i could use reference to take care of this easy. Or char ** to send in the pointer and do it that way. But i just wanted to know if I could do it with just char *. Anyway your thoughts and comments plus any examples would be very helpful.
I'm using Python's subprocess.communicate() to read stdout from a process that runs for about a minute. How can I print out each line of that process's stdout in a streaming fashion, so that I can see the output as it's generated, but still block on the process terminating before continuing? subprocess.communicate() appears to give all the output at once.
I'm doing an java activity that if Name start with letter A-G and Ends with Letter H-z the output is invalid heres my code:
System.out.print("Enter your name: ");
String str = in.readLine();
if(str.startsWith("a" )){
System.out.print("INVALID!");
} if(str.endsWith("h")){
System.out.print("INVALID!");
}
This works but how can i implement letter a to g and h to z
i already try this [a-g] and it not WORK!
Apparently Apple has changed some term in the agreement again.
From http://www.appleoutsider.com/2010/06/10/hello-lua/
section 3.3.2 is now
Unless otherwise approved by Apple in writing, no interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s). Notwithstanding the foregoing, with Apple’s prior written consent, an Application may use embedded interpreted code in a limited way if such use is solely for providing minor features or functionality that are consistent with the intended and advertised purpose of the Application.
instead of the original
No interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s).
I am more interested in embedding Lua, but other people have other embeddings they want to make.
I am wondering how you ask for permission, and what they mean by the terms "minor features" and "consistent" and how will Apple interpret this section? It seems to have enough loopholes to drive a real firetruck through.
I put a wpf textbox inside a combobox to allow the user to enter a custom setting. I can read the keypress in the keydown event, but the text in the textbox does not change. What am I missing?
<ComboBoxItem Name="GridSizeCustom">
<StackPanel Height="30"
Orientation="Horizontal">
<TextBlock Text="Grid Size (8 - 200)"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0"
/>
<TextBox Name="GridSizeBox"
KeyDown="test"
Width="50"
/>
</StackPanel>
</ComboBoxItem>
I step through this event handler when I press a key, but no change to the textbox text:
public void test(Object sender, KeyboardEventArgs e) {
int x = 0;
}
Any help is appreciated. Thanks.
i have a problem regarding the textbox.
i have done the textbox auto expandable but when i insert the text first time then the textbox shrink in size from their original size.but my requirement is that when my text is exceeding the text box length then it auto expand. my code is
<script type="text/javascript">
$(document).ready(function() {
$('.txtStyle').autogrow();
});
</script>
pls somebody suggest how ot is possible
I am using the following code for sending data to database, but it sends the data even the values of the fields are incorrect or empty. So can anyone help me solve this by using php?
Here is my code:
<?php
//Connecting to sql db
$connect = mysqli_connect("localhost","root","","form");
/* check connection */
if (!$connect) {
die('Connect Error: ' . mysqli_connect_error());
}
//Sending data to sql db
$result = mysqli_query($connect,"INSERT INTO students(name,email,website,comment,gender)
VALUES('$name','$email','$website','$comment','$gender')");
if (!$result) {
die('Query Error:'. mysqli_error($connect));
}
?>
Apparently Apple has changed some term in the agreement again.
From http://www.appleoutsider.com/2010/06/10/hello-lua/
section 3.3.2 is now
Unless otherwise approved by Apple in writing, no interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s). Notwithstanding the foregoing, with Apple’s prior written consent, an Application may use embedded interpreted code in a limited way if such use is solely for providing minor features or functionality that are consistent with the intended and advertised purpose of the Application.
instead of the original
No interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s).
I am more interested in embedding Lua, but other people have other embeddings they want to make.
I am wondering how you ask for permission, and what they mean by the terms "minor features" and "consistent" and how will Apple interpret this section? It seems to have enough loopholes to drive a real firetruck through.
(BTW this is a terribly important question for me an my product.)
Hi,
I am searching a character at first occurence in string using the following code.
But, it is taking some time when the character is too long or the character that i am
searching is at far extend, which makes delay in other operations. How could i tackle with
this problem. The code is below here.
Note: attrPtr is a char* which holds a reference to a string containing '"' character at
far extend.
int position = 0;
char qolon = '"';//character to search
while (*(attrPtr + position++) != qolon);
char* attrValue = NULL;
attrValue = (char*)malloc(position * sizeof(char));
strncpy(attrValue, attrPtr, position-1);
Hi again, here is my coding which gives me the error 'warning: unknown conversion type character 0x20 in format'
int subtotal;
long long a,b,c,d,e,f,g,h,i,j,k,l,m;
subtotal = (1*(a+c+e+g+i+k))+(3*(b+d+f+h+j+l));
printf(" = %d % 10 = %d; (10 - %d) % 10 = %lld\n", subtotal,subtotal%10,subtotal%10,m);
any idea why this is wrong?
I've noticed that the Title or Body part is remembered if I come back to the Ask Question page by pressing Back button of my browser.
This feature is available in all browsers I tested, but doesn't exist for the forms in my own projects.
How can I approach that effect?
UPDATE
I still don't have any clue yet,but guess it that some kind of client cache enabled by http headers or javascript?
I put a wpf textbox inside a combobox to allow the user to enter a custom setting. I can read the keypress in the keydown event, but the text in the textbox does not change. What am I missing?
<ComboBoxItem Name="GridSizeCustom">
<StackPanel Height="30"
Orientation="Horizontal">
<TextBlock Text="Grid Size (8 - 200)"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0"
/>
<TextBox Name="GridSizeBox"
KeyDown="test"
Width="50"
/>
</StackPanel>
</ComboBoxItem>
I step through this event handler when I press a key, but no change to the textbox text:
public void test(Object sender, KeyboardEventArgs e) {
int x = 0;
}
Any help is appreciated. Thanks.
I am reading source code of hoard memory allocator, and in the file of gnuwrapper.cpp, there are the following code
#define CUSTOM_MALLOC(x) CUSTOM_PREFIX(malloc)(x)
What's the meaning of CUSTOM_PREFIX(malloc)(x)? is CUSTOM_PREFIX a function? But as a function it didn't defined anywhere. If it's variable, then how can we use variable like var(malloc)(x)?
more code:
#ifndef __GNUC__
#error "This file requires the GNU compiler."
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#ifndef CUSTOM_PREFIX ==> here looks like it's a variable, so if it doesn't define, then define here.
#define CUSTOM_PREFIX
#endif
#define CUSTOM_MALLOC(x) CUSTOM_PREFIX(malloc)(x) ===> what's the meaning of this?
#define CUSTOM_FREE(x) CUSTOM_PREFIX(free)(x)
#define CUSTOM_REALLOC(x,y) CUSTOM_PREFIX(realloc)(x,y)
#define CUSTOM_MEMALIGN(x,y) CUSTOM_PREFIX(memalign)(x,y)
usually, symbolic functions return vectors for vector inputs:
syms('x');
f=x*2;
subs(f,[1 2 3])
outputs: [2 4 6]
but doing
f=sym('0');
subs(f,[1 2 3]);
outputs: 0
and not: [0 0 0]
so basically, my questions is how do I make f behave as a "normal" symbolic function.
I can do something ugly like f=x-x to create a function that always returns zero, but is there a prettier way?