Search Results

Search found 1234 results on 50 pages for 'enum'.

Page 28/50 | < Previous Page | 24 25 26 27 28 29 30 31 32 33 34 35  | Next Page >

  • Java - how to design your own type?

    - by Walter White
    Hi all, Is it possible to design your own Java Type, say an extensible enum? For instance, I have user roles that a certain module uses and then a sub-package provides additional roles. What would be involved on the JDK side of things? Walter

    Read the article

  • RetryCancel MessageBox

    - by mizipzor
    Im using System.Windows.MessageBox.Show() to display a dialog to the user. One overload lets me set the buttons that appear using the System.Windows.MessageBoxButton enum. However, it seems to lack a RetryCancel option that my googling suggests it should have. Am I missing something? How do I display a RetryCancel messagebox?

    Read the article

  • Have problems designing input and output for a calculator app

    - by zoul
    Hello! I am writing a button calculator. I have the code split into model, view and a controller. The model knows nothing about formatting, it is only concerned with numbers. All formatting is done in the view. The model gets its input as keypresses, each keypress is a part of an enum: typedef enum { kButtonUnknown = 0, kButtonMemoryClear = 100, kButtonMemoryPlus = 112, kButtonMemoryMinus = 109, kButtonMemoryRecall = 114, kButtonClear = 99, … }; When the user presses a button (say 1), the model receives a button code (kButtonNum1), adds the corresponding number to a string input buffer ("1") and updates the numeric output value (1.0). The controller then passes the numeric output value to the view that formats it (1). This is all plain, simple and clean, but does not really work. The problem is that when user enters a part of a number (say 0.00, going to enter 0.001), the input does not survive the way through model to view and the display says 0 instead of 0.00. I know why this happens ("0.00"::string parses to 0::double and that gets formatted as 0). What I don’t know is how to design the calculator so that the code stays clean and simple and the numbers will show up on screen exactly as the user types them. I’ve already come with some kind of solution, but that’s essentially a hack and breaks the beautiful and simple flow from the calculator model to the display. Ideas? Current solution keeps track of the calculator state. If the calculator is building a number, I take the calculator input buffer (a string) and directly set the display contents (also a string). Otherwise I take the proper path, ie. take the numeric calculator output, pass it to the view as a double and the view uses its internal formatter to create a string for the display. Example input: input | display | mode ------+---------+------------ 0 | 0 | from string 0. | 0. | from string 0.0 | 0.0 | from string 0.0+ | 0 | from number This is ugly. (1) The calculator has to expose its input buffer and state. (2) The view has to expose its display and allow setting its contents directly using a string. (3) I have to duplicate some of the formatting code to format the string I got from the calculator input buffer. If user enters 12345.000, I have to display 12,345.000 and therefore I’ve got to have a commification code for strings. Yuck.

    Read the article

  • Combined states, FSM

    - by bobobobo
    Not sure this is the right place to ask, but is it "correct" to combine states of an FSM? Say you have an object with enum State { State1 = 1 << 0, State2 = 1 << 1, State3 = 1 << 2 } ; It just so happens that it makes sense to combine states, as in State myState = State1 | State2 ; however in FSM theory is this illegal?

    Read the article

  • Spring AOP pointcut that matches annotation on interface

    - by seanizer
    Hello, this is my first post here, so I apologize in advance for any stupidity on my side. I have a service class implemented in Java 6 / Spring 3 that needs an annotation to restrict access by role. I have defined an annotation called RequiredPermission that has as its value attribute one or more values from an enum called OperationType: public @interface RequiredPermission { /** * One or more {@link OperationType}s that map to the permissions required * to execute this method. * * @return */ OperationType[] value();} public enum OperationType { TYPE1, TYPE2; } package com.mycompany.myservice; public interface MyService{ @RequiredPermission(OperationType.TYPE1) void myMethod( MyParameterObject obj ); } package com.mycompany.myserviceimpl; public class MyServiceImpl implements MyService{ public myMethod( MyParameterObject obj ){ // do stuff here } } I also have the following aspect definition: /** * Security advice around methods that are annotated with * {@link RequiredPermission}. * * @param pjp * @param param * @param requiredPermission * @return * @throws Throwable */ @Around(value = "execution(public *" + " com.mycompany.myserviceimpl.*(..))" + " && args(param)" + // parameter object " && @annotation( requiredPermission )" // permission annotation , argNames = "param,requiredPermission") public Object processRequest(final ProceedingJoinPoint pjp, final MyParameterObject param, final RequiredPermission requiredPermission) throws Throwable { if(userService.userHasRoles(param.getUsername(),requiredPermission.values()){ return pjp.proceed(); }else{ throw new SorryButYouAreNotAllowedToDoThatException( param.getUsername(),requiredPermission.value()); } } The parameter object contains a user name and I want to look up the required role for the user before allowing access to the method. When I put the annotation on the method in MyServiceImpl, everything works just fine, the pointcut is matched and the aspect kicks in. However, I believe the annotation is part of the service contract and should be published with the interface in a separate API package. And obviously, I would not like to put the annotation on both service definition and implementation (DRY). I know there are cases in Spring AOP where aspects are triggered by annotations one interface methods (e.g. Transactional). Is there a special syntax here or is it just plain impossible out of the box. PS: I have not posted my spring config, as it seems to be working just fine. And no, those are neither my original class nor method names. Thanks in advance, Sean PPS: Actually, here is the relevant part of my spring config: <aop:aspectj-autoproxy proxy-target-class="false" /> <bean class="com.mycompany.aspect.MyAspect"> <property name="userService" ref="userService" /> </bean>

    Read the article

  • Detect Client Computer name when an RDP session is open

    - by Ubiquitous Che
    Hey all, My manager has pointed out to me a few nifty things that one of our accounting applications can do because it can load different settings based on the machine name of the host and the machine name of the client when the package is opened in an RDP session. We want to provide similar functionality in one of my company's applications. I've found out on this site how to detect if I'm in an RDP session, but I'm having trouble finding information anywhere on how to detect the name of the client computer. Any pointers in the right direction would be great. I'm coding in C# for .NET 3.5 EDIT The sample code I cobbled together from the advice below - it should be enough for anyone who has a use for the WTSQuerySessionInformation to get a feel for what's going on. Note that this isn't necessarily the best way of doing it - just a starting point that I've found useful. When I run this locally, I get boring, expected answers. When I run it on our local office server in an RDP session, I see my own computer name in the WTSClientName property. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace TerminalServicesTest { class Program { const int WTS_CURRENT_SESSION = -1; static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; static void Main(string[] args) { StringBuilder sb = new StringBuilder(); uint byteCount; foreach (WTS_INFO_CLASS item in Enum.GetValues(typeof(WTS_INFO_CLASS))) { Program.WTSQuerySessionInformation( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, item, out sb, out byteCount); Console.WriteLine("{0}({1}): {2}", item.ToString(), byteCount, sb); } Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } [DllImport("Wtsapi32.dll")] public static extern bool WTSQuerySessionInformation( IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out StringBuilder ppBuffer, out uint pBytesReturned); } enum WTS_INFO_CLASS { WTSInitialProgram = 0, WTSApplicationName = 1, WTSWorkingDirectory = 2, WTSOEMId = 3, WTSSessionId = 4, WTSUserName = 5, WTSWinStationName = 6, WTSDomainName = 7, WTSConnectState = 8, WTSClientBuildNumber = 9, WTSClientName = 10, WTSClientDirectory = 11, WTSClientProductId = 12, WTSClientHardwareId = 13, WTSClientAddress = 14, WTSClientDisplay = 15, WTSClientProtocolType = 16, WTSIdleTime = 17, WTSLogonTime = 18, WTSIncomingBytes = 19, WTSOutgoingBytes = 20, WTSIncomingFrames = 21, WTSOutgoingFrames = 22, WTSClientInfo = 23, WTSSessionInfo = 24, WTSSessionInfoEx = 25, WTSConfigInfo = 26, WTSValidationInfo = 27, WTSSessionAddressV4 = 28, WTSIsRemoteSession = 29 } }

    Read the article

  • [Java Stripes] How can I use List of object with Stripes "option" tag ?

    - by cscsaba242
    Hello, I have a List of object, produced by JPA q.getResultList(). I would like to use it in a drop down, but Stripes "option" tag cant accept List, just Collection, Enum and Map. Im new to Java, that why perhaps the List can translated to each of them but I dont know how can I solve this issue. (Stripes select,option-map,-enumeration, -collection can build up a drop down from previous mentioned input object structures ) Thanks advance

    Read the article

  • How do I convert integers to characters in C#?

    - by Mike Webb
    I am trying to convert an index of 1 to 27 into the corresponding uppercase letter. I know that in C++ I could type this: char letter = 'A' + (char)(myIndex % 27); This same code does not work in C#. How can I accomplish this task in C#? EDIT: I'd rather not have to encode an enum or switch statement for this if there is a better mathematical solution like the one above.

    Read the article

  • Enums in Ruby

    - by auramo
    What's the best way to implement the enum idiom in Ruby? I'm looking for something which I can use (almost) like the Java/C# enums.

    Read the article

  • Correct way to set the driverOptions for Doctrine DBAL configuration in symfony2

    - by yesIcan
    I have set driverOptions in the config file as mentioned in the doctrine DBAL documentation. But this gives and error 1/1 InvalidConfigurationException: Unrecognized options "driverOptions" under "doctrine.dbal.connections.pdoDevCon" My config file is dbal: default_connection: pdoDevCon connections: pdoDevCon: driver: %dev_database_driver% # < host: %dev_database_host% # | port: %dev_database_port% # | Defined in user: %dev_database_user% # | password: %dev_database_password% # < charset: UTF8 driverOptions: {3: 2} mapping_types: enum: string set: string orm: auto_generate_proxy_classes: %kernel.debug% pdoDevCon: connection: pdoDevCon mappings: AcmeDemoBundle: ~ AcmeHelloBundle: ~ I am using PDO::ATTR_ERRMODE as 3 PDO::ERRMODE_EXCEPTION as 2, it does not work even if i use the strings.

    Read the article

  • Is there a way to make ToEnum generic

    - by maxfridbe
    I would like to do this but it does not work. bool TryGetEnum<TEnum, TValue>(TValue value, out TEnum myEnum) { if (Enum.IsDefined(typeof(TEnum), value)) { myEnum = (TEnum)value; return true; } return false; } Example usage: MyEnum mye; bool success = this.TryGetEnum<MyEnum,char>('c',out mye);

    Read the article

  • Reading all compile errors in Windows command-line?

    - by ArdillaRoja
    Noob question, apologies. I'm compiling Java in Windows Vista's command-line and have so many syntax errors that some are being pushed off the top (a lot of 'class, interface or enum expected' errors which leads me to believe it's an obvious syntax mistake early on in the code that I can't spot). Does anyone know how I could get it to display those first errors? Thanks in advance for the help.

    Read the article

  • how to pass an id number string to this class

    - by Phil
    I'm very much a vb person, but have had to use this id number class in c#. I got it from http://www.codingsanity.com/idnumber.htm : using System; using System.Text.RegularExpressions; namespace Utilities.SouthAfrica { /// <summary> /// Represents a South African Identity Number. /// valid number = 7707215230080 /// invalid test number = 1234567891234 /// /// </summary> [Serializable()] public class IdentityNumber { #region Enumerations /// <summary> /// Indicates a gender. /// </summary> public enum PersonGender { Female = 0, Male = 5 } public enum PersonCitizenship { SouthAfrican = 0, Foreign = 1 } #endregion #region Declarations static Regex _expression; Match _match; const string _IDExpression = @"(?<Year>[0-9][0-9])(?<Month>([0][1-9])|([1][0-2]))(?<Day>([0-2][0-9])|([3][0-1]))(?<Gender>[0-9])(?<Series>[0-9]{3})(?<Citizenship>[0-9])(?<Uniform>[0-9])(?<Control>[0-9])"; #endregion #region Constuctors /// <summary> /// Sets up the shared objects for ID validation. /// </summary> static IdentityNumber() { _expression = new Regex(_IDExpression, RegexOptions.Compiled | RegexOptions.Singleline); } /// <summary> /// Creates the ID number from a string. /// </summary> /// <param name="IDNumber">The string ID number.</param> public IdentityNumber(string IDNumber) { _match = _expression.Match(IDNumber.Trim()); } #endregion #region Properties /// <summary> /// Indicates the date of birth encoded in the ID Number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public DateTime DateOfBirth { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int year = int.Parse(_match.Groups["Year"].Value); // NOTE: Do not optimize by moving these to static, otherwise the calculation may be incorrect // over year changes, especially century changes. int currentCentury = int.Parse(DateTime.Now.Year.ToString().Substring(0, 2) + "00"); int lastCentury = currentCentury - 100; int currentYear = int.Parse(DateTime.Now.Year.ToString().Substring(2, 2)); // If the year is after or at the current YY, then add last century to it, otherwise add // this century. // TODO: YY -> YYYY logic needs thinking about if(year > currentYear) { year += lastCentury; } else { year += currentCentury; } return new DateTime(year, int.Parse(_match.Groups["Month"].Value), int.Parse(_match.Groups["Day"].Value)); } } /// <summary> /// Indicates the gender for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonGender Gender { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int gender = int.Parse(_match.Groups["Gender"].Value); if(gender < (int) PersonGender.Male) { return PersonGender.Female; } else { return PersonGender.Male; } } } /// <summary> /// Indicates the citizenship for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonCitizenship Citizenship { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } return (PersonCitizenship) Enum.Parse(typeof(PersonCitizenship), _match.Groups["Citizenship"].Value); } } /// <summary> /// Indicates if the IDNumber is usable or not. /// </summary> public bool IsUsable { get { return _match.Success; } } /// <summary> /// Indicates if the IDNumber is valid or not. /// </summary> public bool IsValid { get { if(IsUsable == true) { // Calculate total A by adding the figures in the odd positions i.e. the first, third, fifth, // seventh, ninth and eleventh digits. int a = int.Parse(_match.Value.Substring(0, 1)) + int.Parse(_match.Value.Substring(2, 1)) + int.Parse(_match.Value.Substring(4, 1)) + int.Parse(_match.Value.Substring(6, 1)) + int.Parse(_match.Value.Substring(8, 1)) + int.Parse(_match.Value.Substring(10, 1)); // Calculate total B by taking the even figures of the number as a whole number, and then // multiplying that number by 2, and then add the individual figures together. int b = int.Parse(_match.Value.Substring(1, 1) + _match.Value.Substring(3, 1) + _match.Value.Substring(5, 1) + _match.Value.Substring(7, 1) + _match.Value.Substring(9, 1) + _match.Value.Substring(11, 1)); b *= 2; string bString = b.ToString(); b = 0; for(int index = 0; index < bString.Length; index++) { b += int.Parse(bString.Substring(index, 1)); } // Calculate total C by adding total A to total B. int c = a + b; // The control-figure can now be determined by subtracting the ones in figure C from 10. string cString = c.ToString() ; cString = cString.Substring(cString.Length - 1, 1) ; int control = 0; // Where the total C is a multiple of 10, the control figure will be 0. if(cString != "0") { control = 10 - int.Parse(cString.Substring(cString.Length - 1, 1)); } if(_match.Groups["Control"].Value == control.ToString()) { return true; } } return false; } } #endregion } } Here is the code from my default.aspx.cs page: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Utilities.Southafrica; <- this is the one i added to public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var someNumber = new IdentityNumber("123456"); <- gives error } } Can someone please tell the syntax for how I pass an id number to the class? Thanks

    Read the article

  • how to pass an id number string to this class (asp.net, c#)

    - by Phil
    I'm very much a vb person, but have had to use this id number class in c#. I got it from http://www.codingsanity.com/idnumber.htm : using System; using System.Text.RegularExpressions; namespace Utilities.SouthAfrica { /// <summary> /// Represents a South African Identity Number. /// valid number = 7707215230080 /// invalid test number = 1234567891234 /// /// </summary> [Serializable()] public class IdentityNumber { #region Enumerations /// <summary> /// Indicates a gender. /// </summary> public enum PersonGender { Female = 0, Male = 5 } public enum PersonCitizenship { SouthAfrican = 0, Foreign = 1 } #endregion #region Declarations static Regex _expression; Match _match; const string _IDExpression = @"(?<Year>[0-9][0-9])(?<Month>([0][1-9])|([1][0-2]))(?<Day>([0-2][0-9])|([3][0-1]))(?<Gender>[0-9])(?<Series>[0-9]{3})(?<Citizenship>[0-9])(?<Uniform>[0-9])(?<Control>[0-9])"; #endregion #region Constuctors /// <summary> /// Sets up the shared objects for ID validation. /// </summary> static IdentityNumber() { _expression = new Regex(_IDExpression, RegexOptions.Compiled | RegexOptions.Singleline); } /// <summary> /// Creates the ID number from a string. /// </summary> /// <param name="IDNumber">The string ID number.</param> public IdentityNumber(string IDNumber) { _match = _expression.Match(IDNumber.Trim()); } #endregion #region Properties /// <summary> /// Indicates the date of birth encoded in the ID Number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public DateTime DateOfBirth { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int year = int.Parse(_match.Groups["Year"].Value); // NOTE: Do not optimize by moving these to static, otherwise the calculation may be incorrect // over year changes, especially century changes. int currentCentury = int.Parse(DateTime.Now.Year.ToString().Substring(0, 2) + "00"); int lastCentury = currentCentury - 100; int currentYear = int.Parse(DateTime.Now.Year.ToString().Substring(2, 2)); // If the year is after or at the current YY, then add last century to it, otherwise add // this century. // TODO: YY -> YYYY logic needs thinking about if(year > currentYear) { year += lastCentury; } else { year += currentCentury; } return new DateTime(year, int.Parse(_match.Groups["Month"].Value), int.Parse(_match.Groups["Day"].Value)); } } /// <summary> /// Indicates the gender for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonGender Gender { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } int gender = int.Parse(_match.Groups["Gender"].Value); if(gender < (int) PersonGender.Male) { return PersonGender.Female; } else { return PersonGender.Male; } } } /// <summary> /// Indicates the citizenship for the ID number. /// </summary> /// <exception cref="System.ArgumentException">Thrown if the ID Number is not usable.</exception> public PersonCitizenship Citizenship { get { if(IsUsable == false) { throw new ArgumentException("ID Number is unusable!", "IDNumber"); } return (PersonCitizenship) Enum.Parse(typeof(PersonCitizenship), _match.Groups["Citizenship"].Value); } } /// <summary> /// Indicates if the IDNumber is usable or not. /// </summary> public bool IsUsable { get { return _match.Success; } } /// <summary> /// Indicates if the IDNumber is valid or not. /// </summary> public bool IsValid { get { if(IsUsable == true) { // Calculate total A by adding the figures in the odd positions i.e. the first, third, fifth, // seventh, ninth and eleventh digits. int a = int.Parse(_match.Value.Substring(0, 1)) + int.Parse(_match.Value.Substring(2, 1)) + int.Parse(_match.Value.Substring(4, 1)) + int.Parse(_match.Value.Substring(6, 1)) + int.Parse(_match.Value.Substring(8, 1)) + int.Parse(_match.Value.Substring(10, 1)); // Calculate total B by taking the even figures of the number as a whole number, and then // multiplying that number by 2, and then add the individual figures together. int b = int.Parse(_match.Value.Substring(1, 1) + _match.Value.Substring(3, 1) + _match.Value.Substring(5, 1) + _match.Value.Substring(7, 1) + _match.Value.Substring(9, 1) + _match.Value.Substring(11, 1)); b *= 2; string bString = b.ToString(); b = 0; for(int index = 0; index < bString.Length; index++) { b += int.Parse(bString.Substring(index, 1)); } // Calculate total C by adding total A to total B. int c = a + b; // The control-figure can now be determined by subtracting the ones in figure C from 10. string cString = c.ToString() ; cString = cString.Substring(cString.Length - 1, 1) ; int control = 0; // Where the total C is a multiple of 10, the control figure will be 0. if(cString != "0") { control = 10 - int.Parse(cString.Substring(cString.Length - 1, 1)); } if(_match.Groups["Control"].Value == control.ToString()) { return true; } } return false; } } #endregion } } Can someone please tell the syntax for how I pass an id number to the class? Thanks

    Read the article

  • Optional Argument: compile time constant issue

    - by Jack
    Why is this working: public int DoesEmailAddressExistsExcludingEmailAddressID( string emailAddress, string invitationCode, int emailAddressID = 0, int For = (int) Enums.FOR.AC) whereas this doesn't public int DoesEmailAddressExistsExcludingEmailAddressID( string emailAddress, string invitationCode, int emailAddressID = 0, int For = Enums.FOR.AC.GetHashCode()) where AC is enum. Can enums's hashcode change at runtime?

    Read the article

  • Needs clarification on C# Flags

    - by Jojo
    Hi guys, i have this code: [Flags] public enum MyUriType { ForParse, ForDownload, Unknown } and then: MyUriType uriType = MyUriType.ForDownload; but, I was wondering why this returns true: if ((uriType & MyUriType.ForParse) == MyUriType.ForParse) When it is not set in the second code group. Please advise.

    Read the article

  • Where to store application global variable?

    - by Shawn Mclean
    I'm using silverlight, project structure is similiar to any other .net app. I have a map control that I would like to store what mode it is in (either road or aerial) so that other controls can access this. Where do I put this enum variable, I plan to use 2 way binding on it so both are updated when either changes. Thanks.

    Read the article

  • Namespace constant in C#

    - by pm_2
    Is there any way to define a contsant variable for an entire namespace, rather than just within a class? For example: namespace MyNamespace { public const string MY_CONST = "Test"; static class Program { } } Gives a compile error as follows: Expected class, delegate, enum, interface, or struct

    Read the article

  • Enumerator problem, Any way to avoid two loops?

    - by pug
    I have a third party api, which has a class that returns an enumerator for different items in the class. I need to remove an item in that enumerator, so I cannot use "for each". Only option I can think of is to get the count by iterating over the enum and then run a normal for loop to remove the items. Anyone know of a way to avoid the two loops? Thanks

    Read the article

  • problem with fifos linux

    - by nunos
    I am having problem debugging why n_bytes in read_from_fifo function in client.c doesn't correspond to the value written to the fifo. It should only write 25 bytes but it tries to read a lot more (1836020505 bytes (!) to be exact). Any idea why this is happening? server.c: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <fcntl.h> #include <sys/wait.h> #include <signal.h> #include <pthread.h> #include <sys/stat.h> typedef enum { false, true } bool; //first read the int with the number of bytes the data will have //then read that number of bytes bool read_from_fifo(int fd, char* var) { int n_bytes; if (read(fd, &n_bytes, sizeof(int))) { printf("going to read %d bytes\n", n_bytes); if (read(fd, var, n_bytes)) printf("read var\n"); else { printf("error in read var. errno: %d\n", errno); exit(-1); } } return true; } int main() { mkfifo("/tmp/foo", 0660); int fd = open("/tmp/foo", O_RDONLY); char var[100]; read_from_fifo(fd, var); printf("var: %s\n", var); return 0; } client.c: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <fcntl.h> typedef enum { false, true } bool; //first write to fd a int with the number of bytes that will be written afterwards bool write_to_fifo(int fd, char* data) { int n_bytes = (strlen(data)) * sizeof(char); printf("going to write %d bytes\n", n_bytes); if (write(fd, &n_bytes, sizeof(int) != -1)) if (write(fd, data, n_bytes) != -1) return true; return false; } int main() { int fd = open("/tmp/foo", O_WRONLY); char data[] = "some random string abcdef"; write_to_fifo(fd, data); return 0; } Help is greatly appreciated. Thanks in advance.

    Read the article

  • Categorize the approximate shape of an array of Points in 3D Space

    - by user1295133
    I have a set of points in 3d space and I want to be able to categorize the shape that best fits them - cube, sphere, cylinder, planar (flat) etc. I've looked at supervised/machine learning but since I need first generate a large training data set that's not really suitable. My dream solution would be a java library with a wonderful magical function something like : public enum ShapeType { CUBE, SPHERE, CYLINDER, PLANAR } public ShapeType CategorizeShapeFromPoints( 3DPoint[] points ) However, any and all help will be appreciated. Thanks

    Read the article

< Previous Page | 24 25 26 27 28 29 30 31 32 33 34 35  | Next Page >