Search the Community
Showing results for tags 'pointers'.
-
1. Budget & Location $800 USD 2. Aim I'm going for an all-around machine for light gaming such as Minecraft (modded), Terraria (also sometimes modded), and some e̶m̶u̶l̶a̶t̶o̶r̶s̶. I will also be using it for CAD with fusion 360 and Autodesk Inventor as well as video editing (1080 mostly) with Filmora 9. 3. Monitors Just one 1080 Asus monitor. Nothing special. 4. Peripherals Already have USB mouse and keyboard. Windows is not an issue. 5. Why are you upgrading? To have an up-to-date pc that is snappy and capable with the programs I run without completely re-fitting my current pc with new parts. I have been using an old prebuilt pc for a long time now and I am looking to upgrade to a new custom one to build myself. This is my first time doing so, so I'm looking for any tips from more experienced people to help or tell me anything I did wrong. My budget is $800 but I can give or take about 50. I just need any tips you might have for different parts than the ones I chose, anything that won't work or I am making difficult for myself, or places I can save money to put towards more important things. The total price of the screenshot is $784.84. P.S. The Seagate Barracuda will just be for extra storage since I have lots of pictures and videos. The SSD will be the main boot drive. The custom prices are from lower priced parts elsewhere.
-
From my understanding a pointer is a variable whose value is a memory address of another variable. And that you declare a pointer like so: int *test; So i know what a pointer is and that it's used for passing by reference, but what confuses me is following where a pointer points to in a program. For example this program: #include<stdio.h> void up_case(char *c) { if (*c>='a' && *c<='z') *c-=32; } void lo_case(char *c) { if (*c>='A' && *c<='Z') *c+=32; } void traverse(char *s, void (*f) (char *)) { while (*s!='\0') { f(s); s++; } } int main() { char str[]="CTEC2901 Data Structure and Algorithms"; printf("Original: \'%s\'\n",str); traverse(str,up_case); printf("Upper Case: \'%s\'\n",str); traverse(str,lo_case); printf("Lower Case: \'%s\'\n",str); return 0; } I do understand this program, but what i don't get is what char *c in the up_case and lo_case function point to, as well as the char *s, void (*f) and char * in the traverse function. My guess is that char *c in the up_case and lo_case point to the value thats given in. The same with the traverse function char *s points to the char array called str, and the *f points is clearly a function pointer so it would point to either lo-case or up_case. Like I said i'm not really sure, so if someone could talk me through where each pointer points to in each function I'd be greatful.
- 7 replies
-
- pointers
- pass by reference
-
(and 3 more)
Tagged with:
-
Hello everyone, So I am doing some exercices about C programming, specifically an introduction to pointers. I have this one exercise: And I am not sure how to go about the initial_address. Should I do something like: char str[]={"This is a string"}; char *index = *str[2]; And then begin to search from index? How would I do that? How do I say that an array starts on the position pointed by the index?
-
Hello everyone, So I have this exercise (on pointers introduction), last one of the exercise sheet I am doing that states: Now I figured I would just run my code until I got to the end of the string (the previous exercise was to just find a single word on a string) but I am not sure how to use the char** addrs, i looked up the uses for the pointer to the pointer but still can't make out how to use it in this case. My code is this: char* find_word(char* str, char* word, char* initial_addr) { int flag=0; char *temp; char* orig = word; while(1){ if(*word == *initial_addr){ if(flag !=1){ temp = initial_addr; } flag = 1; initial_addr++; word++; }else{ if(*initial_addr == ' ' && flag == 1){ return temp; }else{ temp = NULL; } word = orig; flag =0; initial_addr++; } if(*initial_addr == '\0'){ return NULL; } } } Where in the main function I subtract the size of the temp string to the original string and get the address where it starts. Can anybody tell me how I go about this?
-
Hi, I am trying to write a program that will print out the contents of a file. I also wanted to try making the program take an argument in the command line. Here is my code: #include <stdio.h> int readFile(char *infile) { int num; FILE *fptr; fptr = open("/home/students/hansong5/crypter/%c", infile, "r"); if(fptr == NULL) { printf("Error opening file"); } fscanf(fptr, "%d", &num); fclose(fptr); return num; } int main (int argc, char *argv[]) { printf(readFile(argv[1])); return 0; } I am having a number of problems. The first being that this code does not compile without warnings or errors, as shown below: For some reason, when I try to read the file using fopen, I get the error: "too many arguments". I am trying to specify the path name by putting the %c at the end of the path and specifying that it should use the first argument in the command as the path name. Then, I get a warning about making a pointer from an integer when using printf. Should I define a variable outside of the printf statement with the function instead of passing the function inside of the printf statement? The second problem is that when I try to run the code with warnings I get a segmentation fault. I believe that is just because I am misusing the pointers in my code but I'm not sure how to go about fixing this. Any help would be greatly appreciated! Disclaimer: While in my filepath you can see "student" as one of the directories, this particular project is not a homework assignment. I program mostly on a redhat server that the university provides us. I am trying to learn about reading and writing files and writing C programs with arguments on my own time to work on a crypter. I always specify whether or not the code I am sharing is part of a homework assignment because helping with homework may go against some people's ethics. I have post history with homework assignments I've worked on as proof of this.
-
#include<stdio.h> #include<malloc.h> void SError(int); void WriteFile(void(*functionPtr)(int));/* Parameter is function pointer */ int BinaryWriteToFile(void); void main(void) { void(*functionPtr)(int); functionPtr = SError; WriteFile(functionPtr); } void SError(int errorNum) { static char*err[] = { "Cannot Open File\n", "Read Error\n", "Write Error\n"}; puts(err[errorNum]); } void WriteFile(void(*errorFunction) (int)) { int error = BinaryWriteToFile(); if(error)errorFunction(error); } int BinaryWriteToFile(void) { int errorCode = 2;// Fictitiousdisk occurred, report for logging to file via SError... return errorCode; } I want to be able to modify the call-back example,by inserting pointer parameter into the arguments lists of the function calls as required,to return the error-message test to main(). Display the error-message text on-screen in main()before terminating the program. But i am really struggling with where to start etc. Can someone point anything out to me?
-
My friend is trying to get into pc gaming with his first pc but ran it by his uncle in order to order the parts. His uncle who has built PCs before, opted to give my friend some of his old parts. It was just a whole pc, complete with a GTX 660 and god knows what cpu. While he did order a MoBo, cpu, ram, gpu, and ssd; his uncle took it upon himself to not order him the case, psu, or hdd. I’m sure his thinking was to use the stuff he previously owned and as infuriating the hdd and psu are we shrugged it off till it came time to build. We got to the end, the very end, just put the gpu in and everything and... the psu didn’t have the right power for it. The gpu is a power color red devil amd 5700xt and needs two 8 pin connectors for power. I’m trying to look up and find him a psu to order but I’m having trouble confirming if it will work. The MoBo is a Asus x570 tuf gaming and so it needs the 8+4 pin for the cpu too. If anybody can link me a psu on either newegg or amazon around 600 watts or higher as well as semi/fully modular that would be awesome!!
-
Hi! I'm starting to learn c++ because it is a language I respect very much. I knew this was gonna be hard because I came from web development and c#. I can get things done by grabbing pieces of code from here and there and throwing it all in a blender but that's not what I want to do. I've read that it's best to use char arrays instead of strings in almost any case where you don't need to make any alterations to the content itself. But since I started I keep seeing these apparently random asterisks and ampersands all over the place, and I went around reading. I'm having a really hard time understanding the concept of pointers and the more I read the more confused I get. This code: time_t now = time(0); char* dt = ctime(&now); cout << "The local date and time is: " << dt << endl; tm *gmtm = gmtime(&now); dt = asctime(gmtm); cout << "The UTC date and time is:"<< dt << endl; First off why does the * make a char variable a char array variable? Then what does the & before the now mean? What does it do? Apparently if I take it off I get an invalid conversion from time_t to const time_t*. Well now I'm even more confused, what the hell does that * do after const time_t? And what the hell does a constant have to do with any of this? Fourth line, I don't get the functionality of that * before the variable name, but it's gotta be something completely different from char* right? And ofc, there is the & again. I would really appreciate some help with this because I'm overwhelmed and way over my head. Thank you!
-
If you have a dual monitor setup and you have Windows 8.1, you have probably encoutered a problem with your mouse pointer sticking to the edge of the screen when moving from one to the other slowly. Now, if you move it really fast it will get through but if you do it at normal speed it will stick to the edge. Now, this isn't a bug or anything, this is a feature and here is how to fix it. 1. Right click on the windows button and select Run 2. type in regedit Now you want to navigate to here: Now you have to find a DWORD value called MouseMonitorEscapeSpeed and change it's value to 1. (If the value does not exist then create it.) Now you need to navigate to here: HKCU\Software\Microsoft\Windows\CurrentVersion\ImmersiveShell\EdgeUI And repeat what we've done for MouseMonitorEscapeSpeed. After I've done all that it worked for quite a long time but after a while the problem started to appear again. Now what I did to fix it is to creat a .cmd file that refreshes the Registry. Here is how to do it: Open notepad and type in the following: @ taskkill /im explorer.exe /f @ start explorer.exe Then, click File|Save as and save the file as ResetRegistry.cmd (be sure to select All files below the file name): After you've done that you now need to create a shortcut to this file. Here's how you do it: Go to your desktop and right click and select New - Shortcut: Now you need to type in the location of the ResetRegistry.cmd file: Next call it ResetRegistry and you're done. Now all you have to do is restart your PC and the problem will go away. Hope this helped and if you run into any problems feel free to post them below.
-
- dual monitor
- pointers
- (and 4 more)
-
Ok so i'm pretty new at c++ and i'm still learning, but i was wondering if anyone could point me to a place that can give me a good understanding of c++ pointers, i've read several articles and the section of the book that i'm learning from, but i just can't wrap my head around them. so if someone could help that would be appreciated.
-
Hello Linus Tech Tip community! I am a fellow programmer in need of your help. The program I am posting takes in a name and wight for a node and adds the node inorder. There are two pointers, one to sort the names in order and another to sort the weight in order. I have the logic down, but I keep getting the error 'Access violation reading location 0x00000020. I googled it and apparently i'm accessing a null space. I don't now how to fix the problem and if anybody could help that would be great! Oh! The language I used is VisualC++. edit:Formatted the code so it's easier on the eyes. Also, sorry for the title guys. Did't know it would be so abrasive. #include <iostream>#include <string>using namespace std;class node{public: node(); node* getNameNode(); node* getWeightNode(); string getName(); int getWeight(); void setData(string,int); void setNameNode(node*); void setWeightNode(node*);private: int weight; string name; node* nNode; node* wNode;};node::node(){ nNode = wNode = 0; weight = 0; name = "";}node* node::getNameNode(){ return nNode;}node* node::getWeightNode(){ return wNode;}string node::getName(){ return name;}int node::getWeight(){ return weight;}void node::setData(string s, int x){ name = s; weight = x;}void node::setNameNode(node* p){ nNode = p;}void node::setWeightNode(node* p){ wNode = p;}class DoubleLinkList{public: DoubleLinkList(); void addNode(string,int); void print();private: node* nameFront; node* weightFront;};DoubleLinkList::DoubleLinkList(){ nameFront = weightFront = 0;}void DoubleLinkList::addNode(string s, int x){ node* p = new node; p->setData(s,x); if(nameFront==0){ p->setNameNode(0); p->setWeightNode(0); nameFront = weightFront = p; } else{ if(p->getName().compare(nameFront->getName()) > 0){ p->setNameNode(nameFront->getNameNode()); nameFront = p; } else if(p->getWeight() < weightFront->getWeight()){ p->setWeightNode(weightFront->getWeightNode()); weightFront = p; } else{ node* temp = new node; for(temp = nameFront;temp!=0 && p->getName() < temp->getName(){ temp = temp->getNameNode(); } if(temp->getNameNode()==0){ p->setNameNode(0); temp->setNameNode(p); } else{ p->setNameNode(temp->getNameNode()); temp->setNameNode(p); } for(temp = weightFront;temp!=0 && p->getWeight() < temp->getWeight(){ temp = temp->getWeightNode(); } if(temp->getWeightNode()==0){ p->setWeightNode(0); temp->setWeightNode(p); } else{ p->setWeightNode(temp->getWeightNode()); temp->setWeightNode(p); } } }}void DoubleLinkList::print(){ node* p = new node; cout << "Names:" << endl; for(p=nameFront;p!=0;p=p->getNameNode()){ cout << p->getName() << endl; } cout << "Weights:" << endl; for(p=weightFront;p!=0;p=p->getWeightNode()){ cout << p->getWeight() << endl; }}int main(){ DoubleLinkList s; s.addNode("Jim",150); s.addNode("Tom",212); s.addNode("Michael",174); s.addNode("Abe",199); s.addNode("Richard",200); s.addNode("April",117); s.addNode("Claire",124); s.addNode("Bobby",109); s.addNode("Bob",156); s.addNode("Kevin",145); s.addNode("Jason",182); s.addNode("Brian",150); s.addNode("Chris",175); s.addNode("Steven",164); s.addNode("Annabelle",99); s.print(); system("PAUSE"); return 0;}
- 10 replies
-
- c++
- double link list
-
(and 1 more)
Tagged with: