|
Break the problem into simpler tasks and implement functions for these:
1. write a function that reverses a full list. Make sure to adhere to the constraint to only use a constant amount of space (memory).
2. write a function to find the Nth element within a list from a given starting position (not actually needed, but will simplify the final program)
3. write a function to split off part of a given list before the Nth position
4. write code to retrieve sub-lists of length K using 2. and 3. and code to insert a (modified) sublist back at the original position.
5. use 1. and 4. in an iteration to process the entire list
All of these steps can easily be done with the help of at most two or three temporary references (pointers). The only tricky one is the reverse function.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Member 14055543 wrote:
Can anyone point me in the right direction? What code do you have so far? What help have you sought from your instructor? What does the problem/solution look like on paper (don't bother with code until you can complete this step)?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I am facing an issue while printing some text using Ajantha Font, My observation says that after ANSI code 127 GDIPlus is not printing the correct font on windows 10 x64, where as GDI (Direct printing on DC does it correctly).
CFont font;
VERIFY(font.CreateFont(
40, // nHeight
20, // nWidth
0, // nEscapement
0, // nOrientation
FW_DONTCARE, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
FALSE, // cStrikeOut
DEFAULT_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH, // nPitchAndFamily
_T("AJANTHA"))); // lpszFacename
// Do something with the font just created...
CClientDC cdc(this);
CFont* def_font = cdc.SelectObject(&font);
cdc.TextOut(11, 11, _T("€ € ~ ƒ „ …"), 11);
cdc.SelectObject(def_font);
Font mFont(dc.m_hDC, font);
SolidBrush BlueBrush(Color(255, 0, 0, 255));
graphics.DrawString( strText, -1, &mFont, PointF(0, 150), pStringFormat, &BlueBrush);
// Done with the font. Delete the font object.
font.DeleteObject();
|
|
|
|
|
What is contained in strText and what exactly do you see on the output?
|
|
|
|
|
Adding to what has already been said ... read carefully
CreateFontA function | Microsoft Docs[^]
Read this bit carefully
Quote: To ensure consistent results when creating a font, do not specify OEM_CHARSET or DEFAULT_CHARSET. If you specify a typeface name in the lpszFace parameter, make sure that the fdwCharSet value matches the character set of the typeface specified in lpszFace.
Specifically you may want to look at the GDIPLUS font class
CFont Class | Microsoft Docs[^]
Quote: The font mapper does not use the DEFAULT_CHARSET value. An application can use this value to allow the name and size of a font to fully describe the logical font. If a font with the specified name does not exist, a font from any character set can be substituted for the specified font. To avoid unexpected results, applications should use the DEFAULT_CHARSET value sparingly.
Look at the sample code on the page and what setting they use, so what you really want to do for entirely predictable results is specify ANSI_CHARSET and use UNICODE strings, anything else is hit and miss
In vino veritas
modified 13-Nov-18 12:48pm.
|
|
|
|
|
Hi
i am trying to develop an application with following features:
The program starts in an user context, and during execution it will acquire admins rights,
can i accomplish this without the UAC Elevation?
If yes can you drive me to article that explains it?
Thanks in advance
|
|
|
|
|
|
Hello guys I'm trying to code in opengl so if anyone could help ill be posting info below
code:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main(){
glewExperimental = true;
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Failed to open GLFW window. if you have an intel gpu they are not 3.3 compatible try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental=true;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do{
glClear( GL_COLOR_BUFFER_BIT );
glfwSwapBuffers(window);
glfwPollEvents();
}
while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
}
error:
1>------ Rebuild All started: Project: opengl, Configuration: Debug Win32 ------
1> lov.cpp
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\trogd\documents\visual studio 2010\Projects\opengl\Debug\opengl.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
codeproject is what keeps me going :P
|
|
|
|
|
It appears that VS is trying to link before compiling, hence the message as the entry point _main should be created by compiling the above source into its object code. Check your project build settings.
|
|
|
|
|
You have setup a Console project to what is a Win GUI code or vice vesa.
When you first setup the project you had two choices windows console or windows GUI you selected the wrong one, whatever the case.
Not sure why you are staying on VS2010 rather than updating as it's free but on VS2017
You can change it after you make the project via
Project -> Properties -> Configuration Properties -> Linker -> System
It will be something similar on VS2010 and what you are after is subsystem and it will be either
Windows (/SUBSYSTEM:WINDOWS)
OR
Console (/SUBSYSTEM:CONSOLE)
Whichever one it is on currently it's wrong for the project, select the other.
In vino veritas
|
|
|
|
|
Functions to use when creating a mobile app using c++
|
|
|
|
|
|
I am using visual c++.net 2010 I get these errors
1>------ Build started: Project: last try, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\trogd\documents\visual studio 2010\projects\last try\last try\main.cpp(18): warning C4007: 'DllMain' : must be '__stdcall'
1>LINK : fatal error LNK1561: entry point must be defined
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
and here is the code also please tell me what is wrong and how I can fix it. thanks!
#include <Windows.h>
#define ADR_Test 0xB7CE50
void HackThread()
{
for(;;)
{
*(DWORD*)ADR_Test = 100000;
}
Sleep(180);
}
BOOL DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)HackThread, 0, 0, 0);
}
return TRUE;
}
|
|
|
|
|
wrote: BOOL DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID) Should be BOOL __stdcall DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID) or BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID)
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello friends,
I needed some hints/suggestion/brainstorm, so to go in a right direction.
I have lot of different Objects, based on which I need to generate a Text-file. This text is nothing but a Scripting Language with some specific rules or grammars. ( Example, like a VB script ).
A simple/legacy way could be, Iterate all the objects, and Append hard-coded text ( to a global string), with many if and else cases.
Now, I am looking if any framework/design/principle is available, or I can make use of it, to make a clean design/code instead writing lot of if and else. One I found is boost karma, but looking for alternatives to make the best choice.
Seeking your valuable advises.
Thanks in advance,
|
|
|
|
|
Make the object classes inherit from a common interface exposing, say, a toString method an d then call it on all the object instances.
|
|
|
|
|
Thank you for your advice. Sure it is part of the solution.
I was looking more on making the script file ( that is the text of the scripts), as in how should I do that. Shall I simply make a hard-coded string with lot of if and else ( from the objects), and append them one by one, or do we have a fit design Pattern for this. Keeping in mind there would be some rules for the script generation, I would love to make it cleaner with some well design structure.
|
|
|
|
|
If chains can be avoided, if feasible, leveraging on polymorphism.
|
|
|
|
|
Option B is to make a simple program to load them into a database either a standard spec or make your own format.
If you need to do this a lot or need to edit and change the data and save it again then you are effectively dealing with a database you just don't realize it. Say for something like a game often you need leaderboards etc and if you want to deploy on a mobile app you really need to hit one of the cloud databases. So it depends a lot what you are trying to do.
To really be able to give advice we need to know how often is the data accessed .. aka is speed of access an issue or alternatively is the data only ever read once and never touched again AKA its a straight load situation.
In vino veritas
|
|
|
|
|
Thank you so much for your reply.
FYI, there is no db involved, as at the time of making the script all the objects are already available in the memory. I just need to traverse them one by one, make the script out of it.
Keeping in mind there would be rules to make the script, I wish I could do it in a cleaner way ( avoiding lot of if and else while making the text for the script)
|
|
|
|
|
How to create a little game?
|
|
|
|
|
That's not a question we can answer: you do it the same way you do any software project: idea, specification, design, code, test - and move back to any earlier stage as a result of any problems as necessary. The same process occurs if you are producing tic-tac-toe or Skyrim - only the level of detail and the size of the team required changes!
We can't answer "open ended" questions like that - you need to be a whole lot more specific!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
============================================================================
Name : new.c
Author : Abhinav
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
include <stdio.h>
include <stdlib.h>
void compute(int N[6][6],int Z[6][6])
{
//compute neighbours
int i,j;
for (i = 1; i <=6; i++)
{
for (j = 1; j <= 6; j++)
{
N[i][j]=Z[i-1][j-1]+Z[i][j-1]+Z[i+1][j-1]
+ Z[i-1][j] +Z[i+1][j]+ Z[i-1][j+1]
+Z[i][j+1]+Z[i+1][j+1];
}
}
}
// This method is going to print the Matrix that we have defined in the main method
void show(int Z[6][6])
{
printf("************************************************************\n");
int i,j;
// Incrementing the value of integer i so that it can be used as an index value for matrix 'Z'.
for (i = 0; i < 6; i++)
{
// Incrementing the value of integer j to be used as the second index value for matrix 'Z'.
for (j = 0; j < 6; j++)
{
// This will print the elements present in th array line wise.
printf("%d ", Z[i][j]);
}
printf("\n");
}
printf("************************************************************\n");
}
/* This method is going to take the value of elements
from the array and compute the output according to
some conditions. Like for the rule of UnderPopulation
we have to check that if the element at some index is surrounded
by less than two live elements than the element is going to die.
*/
void iteration(int Z[6][6]){
int N[6][6]= {{0}};
int i,j;
compute(N,Z);
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
if((Z[i][j] == 1)&&(N[i][j] < 2 || N[i][j] > 3))
{
Z[i][j] = 0;
}
else if((Z[i][j] == 0)&&(N[i][j] == 3))
{
Z[i][j] = 1;
}
}
}
/*
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
if((N[i][j] < 2 )) // Rule number 1 - Under population
{
if (Z[i][j]==1&&((N[i][j] ==2 )||(N[i][j] == 3 ))) // Rule 4 - Next generation
{
Z[i][j] = 1;
}
else
{
Z[i][j] = 0;
}
}
else if ((Z[i][j] == 0)&&(N[i][j]==3)) // Rule 2 - Dead cell become live
{
Z[i][j] = 1;
}
else if ((N[i][j]>3)) // Rule 3 - Overpopulation
{
Z[i][j] = 0;
}
}
}
*/
}
/*
In this main method all the method are called to execute
all the methods.
*/
int main()
{
// Here I have declared a 6x6, 2D array which contains 36 elements.
int Z[6][6]=
{
// In this array '1' denotes live cell where as '0' denotes dead cell.
{1, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 0, 0},
{0, 1, 0, 1, 0, 0},
{0, 0, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
};
// This will pass the value of elements of array into the method 'show()'
int i;
printf("Here is the array that i have declared for the GAME.\n");
show(Z);
printf("\n");
printf("****************************************************************\n");
printf("Actual output after computing the results\n");
for(i=1; i<= 5; i++) // This will tell us the number of generations to skip before the answer
{
//clear(); //clear screen
iteration(Z);
printf("#################################################");
printf("This is the %d generation",i);
show(Z);
}
printf("****************************************************************\n");
return 0;
}
|
|
|
|
|
|